知识分享
分享创造价值 合作实现共赢

知识分享

当前位置: 首页 > 知识分享

Python Flask小程序文件(图片)上传技巧

发布时间:2019-12-16 21:33:04作者:admin点击:



答应管理员,自己挖的坑自己填...
最近刚好要做一个图片处理的小程序,
后台依然是强大无比的Python Flask,
文件上传小程序也采用multipart/form-data,
后端上无缝衔接,
但小程序前端卡了几分钟,泪奔!

下面就是小程序端的源码:

//点击选择图片  tapImage: function (e) {    var that= this    wx.chooseImage({      success: function (res) {        var tempFilePaths = res.tempFilePaths                that.setData({          filePath: tempFilePaths[0]  //保存图片路径                          })        console.log(tempFilePaths[0])      }    })      },  // 点击浏览  showImage(){    wx.previewImage({      current: '', // 当前显示图片路径      urls: [this.data.filePath] // 需要预览图片的路径    })  },    //上传文件  upload_data(){    var filePath = this.data.filePath    wx.getImageInfo({      src: filePath,      success: function (res) {        console.log(res.width)        console.log(res.height)        if (res.width != 600 && res.height !=900){          console.log('图片大小非600*900')           }        else{          console.log('准备上传...')          wx.uploadFile({            url: 'http://example.weixin.qq.com/upload', //接口地址            filePath: filePath,//文件路径            name: 'file',//文件名,不要修改,Flask直接读取            formData: {              'user': 'test'            }, // 其他表单数据,如地理位置、标题、内容介绍等            success: function (res) {              var data = res.data              console.log('上传成功...')            }          })        }      }    })    },

TOP

QQ客服

18910140161