微信小程序 上传图片
upload:function(){
var that = this
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
console.log(res);
wx.uploadFile({
url: 'http://localhost/tp/index.php/Home/Create/upload',
filePath: res.tempFilePaths[0],
name: 'file',
formData: {
'user': 'test'
},
success: function (res) {
var data = res.data
var path = data.substring(3);
var str = 'http://localhost/tp/' + path;
that.setData({
background: str,
path:str
})
},
fail: function () {
console.log("上传失败")
}
});
}
})
}