{"id":14137,"date":"2024-03-19T11:06:00","date_gmt":"2024-03-19T03:06:00","guid":{"rendered":"https:\/\/92it.top\/?p=14137"},"modified":"2024-03-19T11:06:01","modified_gmt":"2024-03-19T03:06:01","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f-%e5%9b%be%e7%89%87%e5%8f%8a%e8%a7%86%e9%a2%91-%e4%b8%8a%e4%bc%a0%e5%88%b0%e5%90%8e%e5%8f%b0","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=14137","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u56fe\u7247\u53ca\u89c6\u9891 \u4e0a\u4f20\u5230\u540e\u53f0"},"content":{"rendered":"\n<p><strong>\u80cc\u666f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p id=\"u3fcbcd2b\">\u5728<strong>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f<\/strong>\u4e2d\u9700\u8981\u4f7f\u7528\u624b\u673a<strong>\u62cd\u6444\u7167\u7247\u4ee5\u53ca\u89c6\u9891\u4e0a\u4f20\u5230\u540e\u53f0<\/strong>\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u64cd\u4f5c\uff0c\u9700\u8981\u89e3\u51b3\u4ee5\u4e0b\u4e24\u4e2a\u95ee\u9898\uff1a<\/p>\n\n\n\n<ol>\n<li>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5982\u4f55\u62cd\u6444\u7167\u7247\u53ca\u89c6\u9891<\/li>\n\n\n\n<li>\u5982\u4f55\u5c06\u62cd\u6444\u7684\u7167\u7247\u53ca\u89c6\u9891\u4e0a\u4f20\u5230\u540e\u53f0\u8fdb\u884c\u5b58\u50a8<\/li>\n<\/ol>\n\n\n\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p id=\"u6a55746c\">\u524d\u7aef\u5f00\u53d1\uff1a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u539f\u751f<\/p>\n\n\n\n<p id=\"u0f65fd67\">\u540e\u7aef\u5f00\u53d1\uff1aFlask<\/p>\n\n\n\n<p><strong>\u5982\u4f55\u62cd\u6444\u7167\u7247\u53ca\u89c6\u9891<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p id=\"ue82ddf60\">\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5982\u4f55\u62cd\u6444\u7167\u7247\u53ca\u89c6\u9891\uff1a\u4f7f\u7528<code>wx.chooseMedia<\/code>API\u6765\u5b9e\u73b0<\/p>\n\n\n\n<p id=\"u312b396c\">\u8be5API\u7528\u4e8e\u62cd\u6444\u6216\u4ece\u624b\u673a\u76f8\u518c\u4e2d\u9009\u62e9\u56fe\u7247\u6216\u89c6\u9891\uff0c\u6587\u6863\u94fe\u63a5\u4e3a\uff1a<a href=\"https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/api\/media\/video\/wx.chooseMedia.html\">wx.chooseMedia(Object object) | \u5fae\u4fe1\u5f00\u653e\u6587\u6863<\/a><\/p>\n\n\n\n<p id=\"u6ba03ba7\">\u7b80\u5355\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function test()\n{\n  wx.chooseMedia({\n        count: 1,\n        mediaType: ['image'],\n        sourceType: ['camera'],\n        camera: 'back',\n        success(res) {\n          console.log(res)\n        },\n        fail(res){\n          console.log(res)\n        }\n  })\n}\n<\/pre>\n\n\n\n<p>\u4e3b\u8981\u53c2\u6570\u542b\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul>\n<li>count\uff1a\u6700\u591a\u53ef\u4ee5\u9009\u62e9\u7684\u6587\u4ef6\u4e2a\u6570<\/li>\n\n\n\n<li>mediaType\uff1a\u6587\u4ef6\u7c7b\u578b\uff0c\u53ef\u9009\u503c\u4e3a\uff1a[&#8216;image&#8217;]\/[&#8216;video&#8217;]\/[&#8216;image&#8217;,&#8217;video&#8217;]\uff0c\u9ed8\u8ba4\u503c\u4e3a[&#8216;image&#8217;,&#8217;video&#8217;]\uff0c\u610f\u4e3a\u5373\u5141\u8bb8\u62cd\u6444\u56fe\u7247\u4e5f\u5141\u8bb8\u62cd\u6444\u89c6\u9891<\/li>\n\n\n\n<li>sourceType\uff1a\u6587\u4ef6\u6765\u6e90\uff0c\u53ef\u9009\u503c\u4e3a[&#8216;album&#8217;]\/[ &#8216;camera&#8217;]\/[&#8216;album&#8217;, &#8216;camera&#8217;]\uff0c\u9ed8\u8ba4\u503c\u4e3a[&#8216;album&#8217;, &#8216;camera&#8217;]\uff0c\u610f\u4e3a\u5373\u5141\u8bb8\u4ece\u76f8\u518c\u9009\u62e9\uff0c\u4e5f\u5141\u8bb8\u76f4\u63a5\u62cd\u6444<\/li>\n\n\n\n<li>camera\uff1a\u4ec5\u5728 sourceType \u4e3a camera \u65f6\u751f\u6548\uff0c\u4f7f\u7528\u524d\u7f6e\u6216\u540e\u7f6e\u6444\u50cf\u5934\uff0c\u53ef\u9009\u503c\u4e3a&#8217;back&#8217;\/&#8217;front&#8217;\uff0c\u9ed8\u8ba4\u503c\u4e3a&#8217;back&#8217;<\/li>\n<\/ul>\n\n\n\n<p id=\"u8b05c6ef\">\u56de\u8c03\u53c2\u6570res\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul>\n<li>tempFiles\uff1a\u672c\u5730\u4e34\u65f6\u6587\u4ef6\u5217\u8868\uff0c\u5176\u4e2d\u7684tempFilePath\u662f\u672c\u5730\u4e34\u65f6\u6587\u4ef6\u8def\u5f84\uff0c\u4e5f\u662f\u8be5\u793a\u4f8b\u4e2d\u7684\u6838\u5fc3\u53c2\u6570\uff1b<\/li>\n\n\n\n<li>type\uff1a\u6587\u4ef6\u7c7b\u578b<\/li>\n<\/ul>\n\n\n\n<p>\uff08\u66f4\u591a\u53c2\u6570\u4ee5\u53ca\u56de\u8c03\u53c2\u6570\u8bf7\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff09<\/p>\n\n\n\n<p>\u7531\u4e0a\u53ef\u77e5\uff0c\u6211\u4eec\u9996\u9009\u9700\u8981\u8c03\u7528wx.chooseMedia\u51fd\u6570\uff0c\u9009\u62e9\u62cd\u6444\u7167\u7247\u6216\u8005\u89c6\u9891\uff0c\u7136\u540e\u5728\u56de\u8c03\u51fd\u6570\u4e2d\u62ff\u5230\u672c\u5730\u4e34\u65f6\u6587\u4ef6\u8def\u5f84\uff0c\u8fd9\u6837\u5c31\u83b7\u53d6\u5230\u4e86\u62cd\u6444\u7684\u7167\u7247\u6216\u89c6\u9891\uff0c\u4f46\u6211\u4eec\u62ff\u5230\u7684\u5e76\u4e0d\u662f\u4e00\u4e2a\u5b8c\u6574\u7684.png\/.mp4\u6587\u4ef6\uff0c\u800c\u662f\u4e00\u4e2a\u4e34\u65f6\u6587\u4ef6\u94fe\u63a5\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">http:\/\/tmp\/z7bXVKwgyWTKcbc89c663afd501de1d27ed321f8591c.jpg<\/pre>\n\n\n\n<p>\u8fd9\u6837\u7684\u6587\u4ef6\u94fe\u63a5\u53ef\u4ee5\u5728\u5f00\u53d1\u8005\u5de5\u5177\u4e2d\u6253\u5f00\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"590\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-130-1024x590.png\" alt=\"\" class=\"wp-image-14139\" style=\"width:440px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-130-1024x590.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-130-300x173.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-130-768x443.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-130-830x478.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-130-230x133.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-130-350x202.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-130-480x277.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-130.png 1076w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u4f46\u8be5\u94fe\u63a5\u65e0\u6cd5\u5728\u5916\u90e8\u8fdb\u884c\u8bbf\u95ee\uff0c\u56e0\u6b64\u5c31\u6d89\u53ca\u5230\u5982\u4f55\u5c06\u8be5\u94fe\u63a5\u6240\u4ee3\u8868\u7684\u6587\u4ef6\u4e0a\u4f20\u5230\u540e\u53f0\u7684\u95ee\u9898\uff1b<\/p>\n\n\n\n<p>\u8fd9\u6837\u7684\u6587\u4ef6\u5728\u5c0f\u7a0b\u5e8f\u4e2d\u88ab\u79f0\u4e3a\u201d\u672c\u5730\u4e34\u65f6\u6587\u4ef6\u201c\uff0c\u4ec5\u5728\u5f53\u524d\u751f\u547d\u5468\u671f\u5185\u4fdd\u8bc1\u6709\u6548\uff0c\u91cd\u542f\u4e4b\u540e\u4e0d\u4e00\u5b9a\u53ef\u7528\uff1b\u66f4\u591a\u5185\u5bb9\u8bf7\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/framework\/ability\/file-system.html\">\u6587\u4ef6\u7cfb\u7edf | \u5fae\u4fe1\u5f00\u653e\u6587\u6863<\/a><\/p>\n\n\n\n<p><strong>\u5982\u4f55\u4e0a\u4f20\u540e\u53f0\u8fdb\u884c\u5b58\u50a8<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p id=\"ua3f5f773\">\u5982\u4f55\u5c06\u62cd\u6444\u7684\u7167\u7247\u53ca\u89c6\u9891\u4e0a\u4f20\u5230\u540e\u53f0\u8fdb\u884c\u5b58\u50a8\uff1a<\/p>\n\n\n\n<ul>\n<li>\u524d\u7aef\uff1a\u4f7f\u7528<code>wx.uploadFile<\/code>API<\/li>\n\n\n\n<li>\u540e\u7aef\uff1a\u4f7f\u7528<code>request.files['photo'].stream.read()<\/code>\u6765\u8bfb\u53d6\u6587\u4ef6<\/li>\n<\/ul>\n\n\n\n<p><strong>\u524d\u7aef\u4ee3\u7801<\/strong><\/p>\n\n\n\n<p>\u6709\u5173<code>wx.uploadFile<\/code>\u53ef\u4ee5\u53c2\u8003\uff1a<a href=\"https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/api\/network\/upload\/wx.uploadFile.html\">UploadTask | \u5fae\u4fe1\u5f00\u653e\u6587\u6863<\/a><\/p>\n\n\n\n<p>\u4e3b\u8981\u53c2\u6570\u6709\uff1a<\/p>\n\n\n\n<ul>\n<li>url\uff1a\u5f00\u53d1\u8005\u670d\u52a1\u5668\u5730\u5740\uff0c\u5373\u8981\u8bbf\u95ee\u7684\u63a5\u53e3<\/li>\n\n\n\n<li>filePath\uff1a\u8981\u4e0a\u4f20\u7684\u6587\u4ef6\u8def\u5f84\uff08\u672c\u5730\u8def\u5f84\uff09\uff0c\u8fd9\u91cc\u5373\u662f\u901a\u8fc7wx.chooseMedia\u56de\u8c03\u4e2d\u7684tempFilePath<\/li>\n\n\n\n<li>formData\uff1aHTTP \u8bf7\u6c42\u4e2d\u5176\u4ed6\u989d\u5916\u7684 form data\uff0c\u5141\u8bb8\u6211\u4eec\u4f20\u8f93\u6587\u4ef6\u7684\u65f6\u5019\u643a\u5e26\u4e00\u4e9b\u5176\u4ed6\u7684\u53c2\u6570\uff0c\u6bd4\u5982\u8bf4\u6587\u4ef6\u540d\u79f0\uff1b<\/li>\n<\/ul>\n\n\n\n<p>\u56e0\u6b64\u5b8c\u6574\u7684\u524d\u7aef\u4ee3\u7801\u5982\u4e0b\uff08\u4e0a\u4f20\u56fe\u7247\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u62cd\u6444\u7167\u7247\nphotoCapture() {\n    let that = this\n    wx.chooseMedia({\n        count: 1,\n        mediaType: ['image'],\n        sourceType: ['camera'],\n        camera: 'back',\n        success(res) {\n            that.setData({\n                photoLink: res.tempFiles[0].tempFilePath,\n            })\n            console.log(res.tempFiles[0].tempFilePath)\n            console.log('\u56fe\u7247\u62cd\u6444\u6210\u529f')\n            wx.showLoading({\n                title: '\u6b63\u5728\u4e0a\u4f20\u56fe\u7247',\n                mask: true\n            })\n \n            \/\/\u56fe\u7247\u4e0a\u4f20\n            wx.uploadFile({\n                url: 'http:\/\/localhost:5000\/uploadImage',\n                filePath: res.tempFiles[0].tempFilePath,\n                name: 'photo',\n                formData: {\n                    fileName: 'photoTest.png'\n                },\n                success(res) {\n                    wx.showToast({\n                        title: '\u56fe\u7247\u4e0a\u4f20\u6210\u529f',\n                    })\n                }\n            })\n        },\n        fail(res) {\n            console.log('\u56fe\u7247\u62cd\u6444\u5931\u8d25')\n        }\n    })\n}<\/pre>\n\n\n\n<p>\u9996\u5148\u62cd\u6444\u7167\u7247\uff0c\u7136\u540e\u4e0a\u4f20\u6587\u4ef6<\/p>\n\n\n\n<p><strong>\u540e\u7aef\u4ee3\u7801<\/strong><\/p>\n\n\n\n<p id=\"u4706fc28\">\u540e\u7aef\u4f7f\u7528flask\u8fdb\u884c\u5f00\u53d1<\/p>\n\n\n\n<p id=\"ua0b0afcb\">\u901a\u8fc7<code>request.files<\/code>\u6765\u63a5\u6536\u6587\u4ef6<\/p>\n\n\n\n<p id=\"u62b2f3eb\">\u901a\u8fc7<code>request.form<\/code>\u6765\u63a5\u6536<code>wx.uploadFile<\/code>\u7684<code>formData<\/code>\u4e2d\u643a\u5e26\u7684\u6570\u636e<\/p>\n\n\n\n<p id=\"udbd28623\">\u901a\u8fc7<code>write<\/code>\u65b9\u6cd5\u5c06\u63a5\u6536\u5230\u7684\u6587\u4ef6\u4fdd\u5b58\u5230\u672c\u5730<\/p>\n\n\n\n<p id=\"u773c0902\">\u56e0\u6b64\u5b8c\u6574\u7684\u540e\u7aef\u4ee3\u7801\u5982\u4e0b\uff08\u4e0a\u4f20\u56fe\u7247\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">app = Flask(__name__)\n \n@app.route('\/')\ndef hello_world():\n    return 'Hello World'\n \n# \u56fe\u7247\u4e0a\u4f20\n@app.route('\/uploadImage', methods=[\"POST\"])\ndef uploadImage():\n    video = request.files['photo'].stream.read()\n    name = request.form['fileName']\n    if not files_exists(name, 2):\n        file_path = os.getcwd() + '\\\\images\\\\' + name\n        with open(file_path, 'ab') as f:\n            f.write(video)\n        return 'image upload success'\n    else:\n        return 'image already exist'\n \n# \u5224\u65ad\u6587\u4ef6\u662f\u5426\u5df2\u7ecf\u5b58\u5728\ndef files_exists(file_name, choice):\n    if choice == 1:\n        path = os.getcwd() + '\\\\videos\\\\'\n        video_path = os.path.join(path, file_name)\n        return os.path.isfile(video_path)\n    else:\n        path = os.getcwd() + '\\\\images\\\\'\n        image_path = os.path.join(path, file_name)\n        return os.path.isfile(image_path)\n \nif __name__ == '__main__':\n    app.run(host='127.0.0.1', port=5000)<\/pre>\n\n\n\n<p><strong>\u8fd0\u884c\u7ed3\u679c<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u9996\u5148\u542f\u52a8\u540e\u7aef\u670d\u52a1\uff0c\u7136\u540e\u5c0f\u7a0b\u5e8f\u521d\u59cb\u9875\u9762\u5982\u4e0b\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"430\" height=\"686\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-131.png\" alt=\"\" class=\"wp-image-14140\" style=\"width:168px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-131.png 430w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-131-188x300.png 188w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-131-230x367.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-131-350x558.png 350w\" sizes=\"(max-width: 430px) 100vw, 430px\" \/><\/figure><\/div>\n\n\n<p>\u70b9\u51fb\u6309\u94ae\u62cd\u6444\u56fe\u7247\uff0c\u53ef\u4ee5\u770b\u5230\u56fe\u7247\u6210\u529f\u9884\u89c8\u5728\u5c0f\u7a0b\u5e8f\u4e2d\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"520\" height=\"484\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-132.png\" alt=\"\" class=\"wp-image-14141\" style=\"width:196px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-132.png 520w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-132-300x279.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-132-230x214.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-132-350x326.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-132-480x447.png 480w\" sizes=\"(max-width: 520px) 100vw, 520px\" \/><\/figure><\/div>\n\n\n<p>\u5728NetWork\u4e2d\u53ef\u4ee5\u770b\u5230\u63a5\u53e3\u7684\u8fd4\u56de\u503c\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"856\" height=\"358\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-133.png\" alt=\"\" class=\"wp-image-14142\" style=\"width:386px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-133.png 856w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-133-300x125.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-133-768x321.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-133-830x347.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-133-230x96.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-133-350x146.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-133-480x201.png 480w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/figure><\/div>\n\n\n<p>\u56fe\u7247\u4e0a\u4f20\u6210\u529f\uff1b\u5728\u540e\u7aef\u4e5f\u80fd\u770b\u5230\u56fe\u7247\u5df2\u7ecf\u4fdd\u5b58\u4e0b\u6765\u4e86\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1002\" height=\"430\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-134.png\" alt=\"\" class=\"wp-image-14143\" style=\"width:388px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-134.png 1002w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-134-300x129.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-134-768x330.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-134-830x356.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-134-230x99.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-134-350x150.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/03\/image-134-480x206.png 480w\" sizes=\"(max-width: 1002px) 100vw, 1002px\" \/><\/figure><\/div>\n\n\n<p><strong>\u5b8c\u6574\u4ee3\u7801<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u524d\u7aef\u4ee3\u7801<\/strong><\/p>\n\n\n\n<p>index.wxml\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;button type=\"primary\" bind:tap=\"photoCapture\">\u70b9\u51fb\u62cd\u6444\u56fe\u7247&lt;\/button>\n&lt;image src=\"{{photoLink}}\">&lt;\/image>\n&lt;button type=\"primary\" bind:tap=\"videoCapture\">\u70b9\u51fb\u62cd\u6444\u89c6\u9891&lt;\/button>\n&lt;image src=\"{{videoLink}}\">&lt;\/image><\/pre>\n\n\n\n<p>index.wxss\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">page {\n  padding-top: 100rpx;\n  height: 100vh;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n}\nimage{\n  margin-top: 50rpx;\n  margin-bottom: 50rpx;\n  width: 600rpx;\n  height: 400rpx;\n  border: 1px solid black;\n}<\/pre>\n\n\n\n<p>index.js\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Page({\n  data: {\n    photoLink: '',\n    videoLink: '',\n  },\n \n  \/\/\u62cd\u6444\u7167\u7247\n  photoCapture() {\n    let that = this\n    wx.chooseMedia({\n      count: 1,\n      mediaType: ['image'],\n      sourceType: ['camera'],\n      camera: 'back',\n      success(res) {\n        that.setData({\n          photoLink: res.tempFiles[0].tempFilePath,\n        })\n        console.log(res.tempFiles[0].tempFilePath)\n        console.log('\u56fe\u7247\u62cd\u6444\u6210\u529f')\n        wx.showLoading({\n          title: '\u6b63\u5728\u4e0a\u4f20\u56fe\u7247',\n          mask: true\n        })\n \n        \/\/\u56fe\u7247\u4e0a\u4f20\n        wx.uploadFile({\n          url:'http:\/\/localhost:5000\/uploadImage',\n          filePath: res.tempFiles[0].tempFilePath,\n          name: 'photo',\n          formData: {\n            fileName:'photoTest.png'\n          },\n          success(res) {\n            wx.showToast({\n              title: res.data,\n            })\n          }\n        })\n      },\n      fail(res) {\n        console.log('\u56fe\u7247\u62cd\u6444\u5931\u8d25')\n      }\n    })\n  },\n \n  \/\/\u62cd\u6444\u89c6\u9891\n  videoCapture() {\n    let that = this\n    wx.chooseMedia({\n      count: 1,\n      mediaType: ['video'],\n      sourceType: ['camera'],\n      maxDuration: 60,\n      camera: 'back',\n      success(res) {\n        that.setData({\n          videoLink: res.tempFiles[0].thumbTempFilePath\n        })\n        console.log('\u89c6\u9891\u62cd\u6444\u6210\u529f')\n        console.log(res.tempFiles[0].tempFilePath)\n        wx.showLoading({\n          title: '\u6b63\u5728\u4e0a\u4f20\u89c6\u9891',\n          mask: true\n        })\n \n        \/\/\u89c6\u9891\u4e0a\u4f20\n        wx.uploadFile({\n          url:'http:\/\/localhost:5000\/uploadVideo',\n          filePath: res.tempFiles[0].tempFilePath,\n          name: 'video',\n          formData: {\n            fileName:'videoTest.mp4'\n          },\n          success(res) {\n            wx.showToast({\n              title: res.data,\n            })\n          }\n        })\n      },\n      fail(res) {\n        console.log('\u56fe\u7247\u62cd\u6444\u5931\u8d25')\n      }\n    })\n  }\n})<\/pre>\n\n\n\n<p><strong>\u540e\u7aef\u4ee3\u7801<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from flask import Flask, request\nimport os\n \napp = Flask(__name__)\n \n@app.route('\/')\ndef hello_world():\n    return 'Hello World'\n \n@app.route('\/uploadVideo', methods=[\"POST\"])\ndef uploadVideo():\n    video = request.files['video'].stream.read()\n    name = request.form['fileName']\n    if not files_exists(name, 1):\n        file_path = os.getcwd() + '\\\\videos\\\\' + name\n        with open(file_path, 'ab') as f:\n            f.write(video)\n        return 'upload success'\n    else:\n        return 'already exist'\n \n \n@app.route('\/uploadImage', methods=[\"POST\"])\ndef uploadImage():\n    video = request.files['photo'].stream.read()\n    name = request.form['fileName']\n    if not files_exists(name, 2):\n        file_path = os.getcwd() + '\\\\images\\\\' + name\n        with open(file_path, 'ab') as f:\n            f.write(video)\n        return 'upload success'\n    else:\n        return 'already exist'\n \n \ndef files_exists(file_name, choice):\n    if choice == 1:\n        path = os.getcwd() + '\\\\videos\\\\'\n        video_path = os.path.join(path, file_name)\n        return os.path.isfile(video_path)\n    else:\n        path = os.getcwd() + '\\\\images\\\\'\n        image_path = os.path.join(path, file_name)\n        return os.path.isfile(image_path)\n \n \nif __name__ == '__main__':\n    app.run(host='127.0.0.1', port=5000)<\/pre>\n\n\n\n<p>\u6b64\u5916\u6587\u4ef6\u4e0a\u4f20\u5230\u540e\u53f0\u4e5f\u53ef\u4ee5\u91c7\u7528base64\u7f16\u7801\u7684\u65b9\u5f0f\u8fdb\u884c\u4e0a\u4f20<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u5728\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u9700\u8981\u4f7f\u7528\u624b\u673a\u62cd\u6444\u7167\u7247\u4ee5\u53ca\u89c6\u9891\u4e0a\u4f20\u5230\u540e\u53f0\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u64cd\u4f5c\uff0c\u9700\u8981\u89e3\u51b3\u4ee5\u4e0b\u4e24\u4e2a\u95ee\u9898\uff1a \u89e3\u51b3\u65b9\u6848  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/14137"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14137"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/14137\/revisions"}],"predecessor-version":[{"id":14144,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/14137\/revisions\/14144"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}