Dokumentation zur WeChat-Applet-Entwicklung
/ 微信小程序API 上傳、下載
微信小程序API 上傳、下載
wx.uploadFile(OBJECT)
將本地資源上傳到開發(fā)者服務(wù)器。如頁面通過 wx.chooseImage 等接口獲取到一個本地資源的臨時文件路徑后,可通過此接口將本地資源上傳到指定服務(wù)器??蛻舳税l(fā)起一個HTTPS POST請求,其中 Content-Type
為 multipart/form-data
。
OBJECT參數(shù)說明:
示例代碼:
wx.chooseImage({ success:function(res){ var tempFilePaths = res.tempFilePaths; wx.uploadFile({ url: 'http://example.com/upload', filePath: tempFilePaths[0], name:"file", formData:{ "user":"test" } }) } })
wx.downloadFile(OBJECT)
下載文件資源到本地??蛻舳酥苯影l(fā)起一個HTTP GET請求,把下載到的資源根據(jù) type 進(jìn)行處理,并返回文件的本地臨時路徑。
OBJECT參數(shù)說明:
示例代碼:
wx.downloadFile({ url: 'http://example.com/audio/123', type: 'audio', success:function(res){ wx.playVoice({ filePath: res.tempFilePath }) } })