{"id":52025,"date":"2024-12-03T08:42:56","date_gmt":"2024-12-03T00:42:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52025\/"},"modified":"2024-12-03T08:42:56","modified_gmt":"2024-12-03T00:42:56","slug":"uniapp-%e4%b8%ad%e5%a6%82%e4%bd%95%e4%b8%8b%e8%bd%bd%e5%89%8d%e7%ab%af%e7%94%9f%e6%88%90%e7%9a%84-blob-%e7%ba%af%e6%96%87%e6%9c%ac%e6%b5%81%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52025\/","title":{"rendered":"Uniapp \u4e2d\u5982\u4f55\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684 Blob \u7eaf\u6587\u672c\u6d41\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Uniapp \u4e2d\u5982\u4f55\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684 Blob \u7eaf\u6587\u672c\u6d41\uff1f<\/h1>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300aUniapp \u4e2d\u5982\u4f55\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684 Blob \u7eaf\u6587\u672c\u6d41\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241118\/1731923500673b0e2c0027d.jpg\" class=\"aligncenter\" title=\"Uniapp \u4e2d\u5982\u4f55\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684 Blob \u7eaf\u6587\u672c\u6d41\uff1f\u63d2\u56fe\" alt=\"Uniapp \u4e2d\u5982\u4f55\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684 Blob \u7eaf\u6587\u672c\u6d41\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 uniapp \u4e2d\uff0c\u5982\u4f55\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684 blob \u6d41<\/strong><\/p>\n<p>\u8981\u5728 uniapp \u4e2d\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684\u7eaf\u6587\u672c blob \u6d41\uff0c\u9700\u8981\u5c06\u5176\u8f6c\u6362\u4e3a base64 \u7f16\u7801\u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>let reader = new filereader();\nreader.readasdataurl(blob);\nreader.onload = function() {\n  let base64data = reader.result;\n};<\/pre>\n<p><strong>\u5c0f\u7a0b\u5e8f\u73af\u5883\uff1a<\/strong><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u73af\u5883\u4e2d\uff0c\u4f7f\u7528 wx.filesystemmanager.writefilesync \u5c06 base64 \u7f16\u7801\u6570\u636e\u5199\u5165\u4e34\u65f6\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u4f7f\u7528 wx.downloadfile \u4e0b\u8f7d\u4fdd\u5b58\u7684\u672c\u5730\u4e34\u65f6\u6587\u4ef6\u3002\u4e0b\u8f7d\u6210\u529f\u540e\uff0c\u4f7f\u7528 wx.opendocument \u6253\u5f00\u6587\u4ef6\u3002<\/p>\n<p><strong>\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>wx.fileSystemManager.writeFileSync(wx.env.USER_DATA_PATH + '\/tempFile.txt', base64data.split(',')[1], 'base64');\nwx.downloadFile({\n  url: wx.env.USER_DATA_PATH + '\/tempFile.txt',\n  success: function(res) {\n    if (res.statusCode === 200) {\n      wx.openDocument({\n        filePath: res.tempFilePath,\n        success: function(res) {\n          console.log('\u6253\u5f00\u6587\u6863\u6210\u529f');\n        }\n      });\n    }\n  }\n});<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aUniapp \u4e2d\u5982\u4f55\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684 Blob \u7eaf\u6587\u672c\u6d41\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u5f39\u6027\u5e03\u5c40\u4e2d\uff0c\u5b50\u5143\u7d20\u8bbe\u7f6e flex-shrink: 1 \u4f46\u4ecd\u6ea2\u51fa\uff0c\u662f\u4ec0\u4e48\u539f\u56e0\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Uniapp \u4e2d\u5982\u4f55\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684 Blob \u7eaf\u6587\u672c\u6d41\uff1f \u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300aUniapp \u4e2d\u5982\u4f55\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684 Blob \u7eaf\u6587\u672c\u6d41\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01 \u5728 uniapp \u4e2d\uff0c\u5982\u4f55\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684 blob \u6d41 \u8981\u5728 uniapp \u4e2d\u4e0b\u8f7d\u524d\u7aef\u751f\u6210\u7684\u7eaf\u6587\u672c blob \u6d41\uff0c\u9700\u8981\u5c06\u5176\u8f6c\u6362\u4e3a base64 \u7f16\u7801\u5b57\u7b26\u4e32\u3002 \u4ee3\u7801\uff1a let reader = new filereader(); reader.readasdataurl(blob); reader.onload = function() { let base64data = reader.result; }; \u5c0f\u7a0b\u5e8f\u73af\u5883\uff1a \u5728\u5c0f\u7a0b\u5e8f\u73af\u5883\u4e2d\uff0c\u4f7f\u7528 wx.filesystemmanager.writefilesync \u5c06 base64 \u7f16\u7801\u6570\u636e\u5199\u5165\u4e34\u65f6\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u4f7f\u7528 wx.downloadfile \u4e0b\u8f7d\u4fdd\u5b58\u7684\u672c\u5730\u4e34\u65f6\u6587\u4ef6\u3002\u4e0b\u8f7d\u6210\u529f\u540e\uff0c\u4f7f\u7528 wx.opendocument \u6253\u5f00\u6587\u4ef6\u3002 \u4ee3\u7801\uff1a wx.fileSystemManager.writeFileSync(wx.env.USER_DATA_PATH + &#8216;\/tempFile.txt&#8217;, base64data.split(&#8216;,&#8217;)[1], &#8216;base64&#8217;); wx.downloadFile({ url: wx.env.USER_DATA_PATH [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52025","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52025"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52025\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}