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



不得不说,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. })

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值