前端:
legenIndexViewTap: function() {
wx.chooseImage({
count: 1,
sizeType: ['orignal', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var tempFilePaths = res.tempFilePaths[0];
wx.uploadFile({
url: url,
filePath: tempFilePaths,
name: 'imageFile',
formData: {
userId: value1,
filePath:tempFilePaths//后台参数filePath
},
success: function (res) {
var data = res.data
console.log(data)
},
fail:function(){
console.log("fail");
}
});
console.log(tempFilePaths);
},
fail: function () {
console.log("fail");
},
complete: function () {
console.log("complete");
}
})
//wx.navigateTo({
// url: '../doctor/doctor_zone'
// })
}
后台:
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
public Object uploadDiagFile(@RequestParam("imageFile") MultipartFile file, String filePath,String userId) throws IOException {
commonService.uploadWxImge(file.getInputStream(), filePath, userId, "user/diag");
return "success";
}
public void uploadWxImge(InputStream imageFile,String filePath, String userId, String type){
ArrayList<FileInfo> files = new ArrayList<FileInfo>();
ImageInfo file = new ImageInfo();
String fileName = getImgName(filePath);
String ext = filePath.substring(filePath.lastIndexOf(".") + 1);
file.setName(fileName);
file.setExt(ext);
file.setType(type);
file.setRelId(userId);
file.setStream(imageFile);
files.add(file);
if(!Utility.isNullOrEmpty(imageFile)) {
// 图片上传
RemoteImageWithThumbHandler imageThread = new RemoteImageWithThumbHandler(files);
imageThread.start();
}
}
其实下面就是一般图片上传处理了。