前
不得不說,SM.MS圖床,很棒,速度快,免費,并且API也簡潔、高效。
中
查閱微信小程序上傳文件API:
-
wx.chooseImage({
-
success: function(res) {
-
var tempFilePaths = res.tempFilePaths
-
wx.uploadFile({
-
url: 'https://example.weixin.qq.com/upload', //僅為示例,非真實的接口地址
-
filePath: tempFilePaths[0],
-
name: 'file',
-
formData:{
-
'user': 'test'
-
},
-
success: function(res){
-
var data = res.data
-
//do something
-
}
-
})
-
}
-
})
SM.MS圖床上傳API:
-
POST https://sm.ms/api/upload
-
smfile=文件數據
后
所以,我們可以很輕易地進行結合,得出最終的API,選擇圖片后上傳到SM.MS圖床并且返回相應數據:
-
wx.chooseImage({
-
success: ret => {
-
var filePath = ret.tempFilePaths[0];
-
wx.uploadFile({
-
url: 'https://sm.ms/api/upload',
-
filePath: filePath,
-
name: 'smfile',
-
success: res => {
-
console.log('上傳成功:', res);
-
}
-
});
-
}
-
})
|