var uploadTask = wx.request({
url: 'http://127.0.0.1:5000/getimage',
data:{
//this.data.src本地上传的图片所在的路径
file: JSON.stringify(this.data.src)
},
method: "POST",
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
console.log(res.data);
}
微信小程序开发工具报错:
Spyder端:
import os.path
from flask import Flask
from flask import app,request
app = Flask(__name__) #创建1个Flask实例
basedir = os.path.abspath(os.path.dirname(__file__)) #定义一个根目录 用于保存图片用
@app.route('/getimage',methods=['POST'])
def getimage():
#获取图片文件 name = file
img = request.files.get('file')
#定义一个图片存放的位置 存放在static下面
path = basedir+"/static/img/"
#图片名称
imgName = img.filename
#图片path和名称组成图片的保存路径
file_path = path+imgName
#保存图片
img.save(file_path)
#url是图片的路径
url = '/static/img/'+imgName
return url
if __name__ == "__main__":
app.run()
IPython console报错: