{"id":28781,"date":"2025-04-20T02:50:56","date_gmt":"2025-04-19T18:50:56","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/28781.html"},"modified":"2025-04-20T02:50:56","modified_gmt":"2025-04-19T18:50:56","slug":"uniapp%e4%b8%ad%e7%9a%84uni-file-picker%e7%bb%84%e4%bb%b6%e4%b8%8a%e4%bc%a0%e5%a4%9a%e5%bc%a0%e5%9b%be%e7%89%87%e5%88%b0%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/28781.html","title":{"rendered":"uniapp\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u4e0a\u4f20\u591a\u5f20\u56fe\u7247\u5230\u670d\u52a1\u5668"},"content":{"rendered":"<p>\u7531\u4e8e\u5728uniapp\u5b98\u65b9\u6587\u6863\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u53ef\u5b9e\u73b0\u56fe\u7247\u4e0a\u4f20\u529f\u80fd&#xff0c;\u9ed8\u8ba4\u7684\u662f\u4e0a\u4f20\u5230\u81ea\u5e26\u7684\u670d\u52a1&#xff0c;\u6240\u4ee5\u6211\u4eec\u8981\u4fee\u6539\u6210\u81ea\u5df1\u7684\u670d\u52a1\u5668<\/p>\n<p>1. \u6dfb\u52a0\u00a0\u00a0:auto-upload&#061;&#034;false&#034;\u00a0 \u00a0\u52a0\u4e0a\u8fd9\u4e2a\u53d6\u6d88\u81ea\u52a8\u4e0a\u4f20<\/p>\n<p>&lt;uni-file-picker v-model&#061;&#034;jobAddUpdateForm.imageList&#034; :auto-upload&#061;&#034;false&#034;  fileMediatype&#061;&#034;image&#034; limit&#061;&#034;9&#034; :image-styles&#061;&#034;imageStyles&#034; &#064;select&#061;&#034;successData&#034;&gt;<br \/>\n&lt;\/uni-file-picker&gt; <\/p>\n<p>2.vue2 \u5c01\u88c5mixin &#xff08;vue3 \u53ef\u4ee5\u5c01\u88c5 hooks&#xff09; \u65b9\u4fbf\u540e\u671f\u8c03\u7528<\/p>\n<p>import config from &#039;&#064;\/config&#039;;<br \/>\nimport {<br \/>\ngetToken<br \/>\n} from &#039;&#064;\/utils\/auth&#039;; \/\/ \u5bfc\u5165\u83b7\u53d6 token \u7684\u51fd\u6570  <\/p>\n<p>\/\/ \u4e0a\u4f20\u56fe\u7247\u7684\u5f02\u6b65\u51fd\u6570<br \/>\nconst uploadImg &#061; async function(tempFilePaths) {<br \/>\nconst baseUrl &#061; config.baseUrl; \/\/ \u57fa\u7840 URL \u4ece\u914d\u7f6e\u4e2d\u83b7\u53d6<br \/>\nconst token &#061; getToken(); \/\/ \u4f7f\u7528 getToken \u51fd\u6570\u83b7\u53d6 token<br \/>\nconst successfulUploads &#061; []; \/\/ \u6570\u7ec4\u7528\u4e8e\u8bb0\u5f55\u6240\u6709\u6210\u529f\u4e0a\u4f20\u7684\u6587\u4ef6\u8def\u5f84  <\/p>\n<p>if (!tempFilePaths.length) return []; \/\/ \u5982\u679c\u6ca1\u6709\u9009\u62e9\u56fe\u7247\u5c31\u9000\u51fa&#xff0c;\u8fd4\u56de\u7a7a\u6570\u7ec4  <\/p>\n<p>\/\/ \u904d\u5386\u9009\u62e9\u7684\u56fe\u7247\u8def\u5f84<br \/>\nfor (const path of tempFilePaths) {<br \/>\ntry {<br \/>\n\/\/ \u8c03\u7528\u63a5\u53e3\u4e0a\u4f20\u6bcf\u4e00\u5f20\u56fe\u7247<br \/>\nconst [err, {<br \/>\ndata<br \/>\n}] &#061; await uni.uploadFile({<br \/>\nurl: &#096;${baseUrl}\/common\/upload&#096;, \/\/ \u81ea\u5df1\u7684\u540e\u53f0\u5730\u5740<br \/>\nfilePath: path,<br \/>\nname: &#039;file&#039;,<br \/>\nheader: { \/\/ \u6dfb\u52a0\u8bf7\u6c42\u5934<br \/>\n&#039;Authorization&#039;: &#096;Bearer ${token}&#096;, \/\/ \u5047\u8bbe\u4f60\u4f7f\u7528\u7684\u662f Bearer \u8ba4\u8bc1<br \/>\n\/\/ \u53ef\u4ee5\u6dfb\u52a0\u5176\u4ed6\u9700\u8981\u7684\u8bf7\u6c42\u5934<br \/>\n},<br \/>\n});<\/p>\n<p>\/\/ \u5904\u7406\u9519\u8bef\u60c5\u51b5<br \/>\nif (err) {<br \/>\nconsole.error(&#039;\u4e0a\u4f20\u9519\u8bef:&#039;, err);<br \/>\ncontinue; \/\/ \u5982\u679c\u4e0a\u4f20\u51fa\u9519&#xff0c;\u7ee7\u7eed\u4e0a\u4f20\u4e0b\u4e00\u5f20\u56fe\u7247<br \/>\n}<br \/>\n  \/\/ \u628a\u8fd4\u56de\u7684\u6570\u636e\u8f6c\u4e3a\u5bf9\u8c61\u683c\u5f0f<br \/>\nconst dataObj &#061; JSON.parse(data);<br \/>\nconsole.log(dataObj)<br \/>\n\/\/ \u5c06\u6bcf\u4e2a\u4e0a\u4f20\u6210\u529f\u7684\u6587\u4ef6\u8def\u5f84\u6dfb\u52a0\u5230\u6570\u7ec4\u4e2d<br \/>\nsuccessfulUploads.push(dataObj); \/\/ \u5047\u8bbe dataObj.data \u662f\u4e0a\u4f20\u540e\u7684\u6587\u4ef6\u8def\u5f84<br \/>\n} catch (error) {<br \/>\nconsole.error(&#039;\u5904\u7406\u4e0a\u4f20\u65f6\u53d1\u751f\u9519\u8bef:&#039;, error);<br \/>\ncontinue; \/\/ \u6355\u83b7\u4e0a\u4f20\u9519\u8bef\u5e76\u7ee7\u7eed<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ \u8fd4\u56de\u6240\u6709\u6210\u529f\u4e0a\u4f20\u7684\u6587\u4ef6\u8def\u5f84<br \/>\nreturn successfulUploads;<br \/>\n};<\/p>\n<p>\/\/ \u5bfc\u51fa uploadImg \u51fd\u6570<br \/>\nexport default uploadImg; <\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f \u8bf7\u6c42\u7684url ,\u9700\u8981\u6362\u6210\u81ea\u5df1\u7684\u63a5\u53e3\u5730\u5740<\/p>\n<p>3. \u5728\u4f7f\u7528\u7684\u5730\u65b9\u5f15\u5165\u5c31\u53ef\u4ee5\u4e86<\/p>\n<p>import uploadImg from &#039;&#064;\/mixin\/imageData.js&#039;;<\/p>\n<p>\/\/ \u4e0a\u4f20\u63a5\u53e3<br \/>\nasync successData(e){<br \/>\nconst res &#061; await uploadImg.call(this, e.tempFilePaths)<br \/>\nconsole.log(res)<br \/>\n} <\/p>\n<p>\u5c31\u53ef\u4ee5\u8fd4\u56de\u4e0a\u4f20\u7684\u4fe1\u606f\u4e86<\/p>\n<\/p>\n<p>\u53c2\u8003&#xff1a;uniapp\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u4e0a\u4f20\u591a\u5f20\u56fe\u7247\u5230\u670d\u52a1\u5668&#xff0c;\u53ef\u6dfb\u52a0&#xff0c;\u9884\u89c8&#xff0c;\u5220\u9664\u56fe\u7247_uni-file-picker\u8be6\u7ec6\u4f7f\u7528\u6559\u5b66-CSDN\u535a\u5ba2<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3k\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf2\u6b21\u30022.vue2 \u5c01\u88c5mixin \uff08vue3 \u53ef\u4ee5\u5c01\u88c5 hooks\uff09 \u65b9\u4fbf\u540e\u671f\u8c03\u7528\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f \u8bf7\u6c42\u7684url ,\u9700\u8981\u6362\u6210\u81ea\u5df1\u7684\u63a5\u53e3\u5730\u5740\u30023. \u5728\u4f7f\u7528\u7684\u5730\u65b9\u5f15\u5165\u5c31\u53ef\u4ee5\u4e86\u3002\u5c31\u53ef\u4ee5\u8fd4\u56de\u4e0a\u4f20\u7684\u4fe1\u606f\u4e86\u3002\u52a0\u4e0a\u8fd9\u4e2a\u53d6\u6d88\u81ea\u52a8\u4e0a\u4f20\u3002_uniapp uni-file-picker<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[387,87],"topic":[],"class_list":["post-28781","post","type-post","status-publish","format-standard","hentry","category-server","tag-uni-app","tag-87"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>uniapp\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u4e0a\u4f20\u591a\u5f20\u56fe\u7247\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/28781.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"uniapp\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u4e0a\u4f20\u591a\u5f20\u56fe\u7247\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3k\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf2\u6b21\u30022.vue2 \u5c01\u88c5mixin \uff08vue3 \u53ef\u4ee5\u5c01\u88c5 hooks\uff09 \u65b9\u4fbf\u540e\u671f\u8c03\u7528\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f \u8bf7\u6c42\u7684url ,\u9700\u8981\u6362\u6210\u81ea\u5df1\u7684\u63a5\u53e3\u5730\u5740\u30023. \u5728\u4f7f\u7528\u7684\u5730\u65b9\u5f15\u5165\u5c31\u53ef\u4ee5\u4e86\u3002\u5c31\u53ef\u4ee5\u8fd4\u56de\u4e0a\u4f20\u7684\u4fe1\u606f\u4e86\u3002\u52a0\u4e0a\u8fd9\u4e2a\u53d6\u6d88\u81ea\u52a8\u4e0a\u4f20\u3002_uniapp uni-file-picker\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/28781.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-19T18:50:56+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/28781.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/28781.html\",\"name\":\"uniapp\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u4e0a\u4f20\u591a\u5f20\u56fe\u7247\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-19T18:50:56+00:00\",\"dateModified\":\"2025-04-19T18:50:56+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/28781.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/28781.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/28781.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"uniapp\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u4e0a\u4f20\u591a\u5f20\u56fe\u7247\u5230\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"uniapp\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u4e0a\u4f20\u591a\u5f20\u56fe\u7247\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/28781.html","og_locale":"zh_CN","og_type":"article","og_title":"uniapp\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u4e0a\u4f20\u591a\u5f20\u56fe\u7247\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3k\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf2\u6b21\u30022.vue2 \u5c01\u88c5mixin \uff08vue3 \u53ef\u4ee5\u5c01\u88c5 hooks\uff09 \u65b9\u4fbf\u540e\u671f\u8c03\u7528\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f \u8bf7\u6c42\u7684url ,\u9700\u8981\u6362\u6210\u81ea\u5df1\u7684\u63a5\u53e3\u5730\u5740\u30023. \u5728\u4f7f\u7528\u7684\u5730\u65b9\u5f15\u5165\u5c31\u53ef\u4ee5\u4e86\u3002\u5c31\u53ef\u4ee5\u8fd4\u56de\u4e0a\u4f20\u7684\u4fe1\u606f\u4e86\u3002\u52a0\u4e0a\u8fd9\u4e2a\u53d6\u6d88\u81ea\u52a8\u4e0a\u4f20\u3002_uniapp uni-file-picker","og_url":"https:\/\/www.wsisp.com\/helps\/28781.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-19T18:50:56+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/28781.html","url":"https:\/\/www.wsisp.com\/helps\/28781.html","name":"uniapp\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u4e0a\u4f20\u591a\u5f20\u56fe\u7247\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-19T18:50:56+00:00","dateModified":"2025-04-19T18:50:56+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/28781.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/28781.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/28781.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"uniapp\u4e2d\u7684uni-file-picker\u7ec4\u4ef6\u4e0a\u4f20\u591a\u5f20\u56fe\u7247\u5230\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/28781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=28781"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/28781\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=28781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=28781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=28781"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=28781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}