{"id":672,"date":"2018-02-24T16:23:17","date_gmt":"2018-02-24T08:23:17","guid":{"rendered":"http:\/\/60.205.208.74\/?p=672"},"modified":"2018-02-24T16:23:17","modified_gmt":"2018-02-24T08:23:17","slug":"js%e5%a4%84%e7%90%86%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0%e6%85%a2%e9%80%a0%e6%88%90%e7%9a%84%e7%94%a8%e6%88%b7%e4%bd%93%e9%aa%8c%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=672","title":{"rendered":"js\u5904\u7406\u6587\u4ef6\u4e0a\u4f20\u6162\u9020\u6210\u7684\u7528\u6237\u4f53\u9a8c\u95ee\u9898"},"content":{"rendered":"<span itemprop=\"description\"><p>\u5728\u7f51\u901f\u6162\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u6587\u4ef6\u4e0a\u4f20\u6162\u9020\u6210\u7528\u6237\u4f53\u9a8c\u5dee\u7684\u95ee\u9898\uff0c\u6211\u8fd9\u91cc\u5b9e\u8df5\u7684\u65b9\u6848\u6709\u4e09\u79cd\uff1a<\/p>\n<ol>\n<li>\u524d\u7aef\u4f7f\u7528ajax\u00a0 \u7684\u65b9\u5f0f\u5f02\u6b65\u628a\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u7aef\uff0c\u7136\u540e\u670d\u52a1\u7aef\u518d\u5bf9\u6587\u4ef6\u8bfb\u5199\u8fdb\u884c\u5f02\u6b65IO. \u6bd4\u5982\u53ef\u4ee5\u4f7f\u7528queue or asyc job or schedual\uff0c\u8fd9\u6837\u524d\u7aef\u80fd\u6709\u8f83\u5feb\u7684\u54cd\u5e94\u3002<\/li>\n<li>\u524d\u7aef\u4f7f\u7528js\u5bf9\u6587\u4ef6\u8fdb\u884cencode\u8f6c\u7801\uff0c\u628a\u6587\u4ef6\u8f6c\u6210\u5b57\u7b26\u8fdb\u884c\u63d0\u4ea4\uff0c\u540e\u7aef\u5728\u8fdb\u884cdecode and IO. \u8fd9\u79cd\u65b9\u5f0f\u6bd4\u5982\u4f7f\u7528base64, \u4f46\u662fbase64 encode to string \u53ef\u80fd\u6709\u65f6\u5019\u5b57\u7b26\u4e32\u4f1a\u6bd4\u8f83\u957f\uff0c\u53ef\u80fd\u4f1a\u8d85\u8fc7\u4e00\u4e9b\u5e94\u7528\u670d\u52a1\u5668\u7684IO\u5927\u5c0f\u8bbe\u7f6e\u3002<\/li>\n<li>\u6700\u8fd1\u53d1\u73b0\u7b2c\u4e09\u79cd\u65b9\u5f0f\u53ef\u4ee5\u66f4\u597d\u7684\u4f53\u9a8c\uff1aplupload,\u00a0http:\/\/www.plupload.com\/,\u8fd9\u662f\u4f7f\u7528flash or sliverlight\u548cHTML5\u7279\u6027\u505a\u7684\u4e0a\u4f20\u63d2\u4ef6\uff0c\u5b9e\u8d28\u8fd8\u662f\u5bf9\u6587\u6863\u8fdb\u884c\u4e86\u8f6c\u7801\u5904\u7406<\/li>\n<li>\u5728\u4e0d\u8003\u8651\u6d4f\u89c8\u5668\u517c\u5bb9\u6027\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528html5\u7684file\u00a0 readAsArrayBuffer\u00a0 or \u4f7f\u7528Btoa<\/li>\n<\/ol>\n<p>js encode file code :<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"js\">&lt;div&gt;\n    &lt;div&gt;\n        &lt;label for=\"filePicker\"&gt;Choose or drag a file:&lt;\/label&gt;&lt;br&gt;\n        &lt;input type=\"file\" id=\"filePicker\"&gt;\n    &lt;\/div&gt;\n    &lt;br&gt;\n    &lt;div&gt;\n        &lt;h1&gt;Base64 encoded version&lt;\/h1&gt;\n        &lt;textarea id=\"base64textarea\" placeholder=\"Base64 will appear here\" cols=\"50\" rows=\"15\"&gt;&lt;\/textarea&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n&lt;script&gt;\nvar handleFileSelect = function(evt) {\n    var files = evt.target.files;\n    var file = files[0];\n\n    if (files &amp;&amp; file) {\n        var reader = new FileReader();\n\n        reader.onload = function(readerEvt) {\n            var binaryString = readerEvt.target.result;\n            document.getElementById(\"base64textarea\").value = btoa(binaryString);\n        };\n\n        reader.readAsBinaryString(file);\n    }\n};\n\nif (window.File &amp;&amp; window.FileReader &amp;&amp; window.FileList &amp;&amp; window.Blob) {\n    document.getElementById('filePicker').addEventListener('change', handleFileSelect, false);\n} else {\n    alert('The File APIs are not fully supported in this browser.');\n}\n&lt;\/script&gt;\n\nrel:http:\/\/jsfiddle.net\/eliseosoto\/JHQnk\/\nhttps:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Base64_encoding_and_decoding\n\u53e6\u5916\uff0c\u53c2\u8003\u4ee3\u7801\uff1a<\/pre>\n<pre class=\"Jquery\">$(document).ready(function($) {\n    $.extend( true, jQuery.fn, {        \n        imagePreview: function( options ){          \n            var defaults = {};\n            if( options ){\n                $.extend( true, defaults, options );\n            }\n            $.each( this, function(){\n                var $this = $( this );              \n                $this.bind( 'change', function( evt ){\n\n                    var files = evt.target.files; \/\/ FileList object\n                    \/\/ Loop through the FileList and render image files as thumbnails.\n                    for (var i = 0, f; f = files[i]; i++) {\n                        \/\/ Only process image files.\n                        if (!f.type.match('image.*')) {\n                        continue;\n                        }\n                        var reader = new FileReader();\n                        \/\/ Closure to capture the file information.\n                        reader.onload = (function(theFile) {\n                            return function(e) {\n                                \/\/ Render thumbnail.\n                                    $('#imageURL').attr('src',e.target.result);                         \n                            };\n                        })(f);\n                        \/\/ Read in the image file as a data URL.\n                        reader.readAsDataURL(f);\n                    }\n\n                });\n            });\n        }   \n    });\n    $( '#fileinput' ).imagePreview();\n});<\/pre>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u65b9\u6848\uff0c\u4ec5\u4f9b\u53c2\u8003\uff0c\u6b22\u8fce\u8ba8\u8bba<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/dl.iteye.com\/topics\/download\/41dc0b0b-158c-3242-bdd6-10bc1452285d\">\u4e0a\u4f20\u7684\u6587\u4ef6plupload<\/a><\/p>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">\u5728\u7f51\u901f\u6162\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u6587\u4ef6\u4e0a\u4f20\u6162\u9020\u6210\u7528\u6237\u4f53\u9a8c\u5dee\u7684\u95ee\u9898\uff0c\u6211\u8fd9\u91cc\u5b9e\u8df5\u7684\u65b9\u6848\u6709\u4e09\u79cd\uff1a \u524d\u7aef\u4f7f\u7528aj&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=672\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39,9,12],"tags":[41,70,77,103],"class_list":["post-672","post","type-post","status-publish","format-standard","hentry","category-js","category-9","category-blog","tag-ajax","tag-html5","tag-jquery","tag-plupload","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=672"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/672\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}