微信小程式 wx.uploadFile(object), wx.downloadFile(object) API
阿新 • • 發佈:2019-01-05
反正我是沒有測通這兩個API!!!!不知道用的方式不對還是其他的!!!先記錄下回頭再說。。。
主要方法:
wx.uploadFile(OBJECT)上傳
wx.downloadFile(OBJECT)下載
wxml
<button type="primary" bindtap="listenerButtonDownLoadFile">下載圖片</button>
<image src="{{resource}}" style="width:100%; height: 80%"/>
- 1
- 2
- 3
- 1
- 2
- 3
js
Page({
data:{
// text:"這是一個頁面"
resource: ''
},
onLoad:function(options){
// 頁面初始化 options為頁面跳轉所帶來的引數
},
/**
* 下載檔案
*/
listenerButtonDownLoadFile: function() {
var that = this;
wx.downloadFile({
url: 'https://t2.27270.com/uploads/tu/201609/240/1mb2dybkw2x.jpg',
type: 'image',
success:function (res){
console.log(res.tempFilePath);
that.setData({
resource: res.tempFilePath,
})
},
fail:function(err){
console.log(err)
},
complete:function(e) {
console.log(e)
}
})
}
})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31