欢迎光临,了解微信小程序开发,就上易用通!

微信小程序使用SM.MS免费图床进行上传删除图片操作

发布:2018-06-11 11:47浏览: 来源:网络 作者:cola

前不得不说,SM.MS图床,很棒,速度快,免费,并且API也简洁、高效。中查阅微信小程序上传文件API:wx.chooseImage({ success: function(res) { var tempFilePaths = res.tempFilePaths wx.uploadFile({ url: 'https ...

 
 
 

不得不说,SM.MS图床,很棒,速度快,免费,并且API也简洁、高效。

 

查阅微信小程序上传文件API:

 

						
  1. wx.chooseImage({
  2. success: function(res) {
  3. var tempFilePaths = res.tempFilePaths
  4. wx.uploadFile({
  5. url: 'https://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
  6. filePath: tempFilePaths[0],
  7. name: 'file',
  8. formData:{
  9. 'user': 'test'
  10. },
  11. success: function(res){
  12. var data = res.data
  13. //do something
  14. }
  15. })
  16. }
  17. })

SM.MS图床上传API:

 

						
  1. POST https://sm.ms/api/upload
  2. smfile=文件数据
 

所以,我们可以很轻易地进行结合,得出最终的API,选择图片后上传到SM.MS图床并且返回相应数据:

 

						
  1. wx.chooseImage({
  2. success: ret => {
  3. var filePath = ret.tempFilePaths[0];
  4. wx.uploadFile({
  5. url: 'https://sm.ms/api/upload',
  6. filePath: filePath,
  7. name: 'smfile',
  8. success: res => {
  9. console.log('上传成功:', res);
  10. }
  11. });
  12. }
  13. })





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。