您的位置:首页 > 编程语言 > Java开发

小程序图片上传整合springmvc

2017-09-13 11:13 267 查看
前端:

 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();
}
}

其实下面就是一般图片上传处理了。 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: