小程序代码
upload:function(e){
var that = this;
wx.showActionSheet({
itemList: ['从相册选择','拍照'],
itemColor:"#f7982a",
success:function(res){
if(!res.cancer){
if (res.tapIndex==0){
that.chooseWxImageShop('album');
} else if (res.tapIndex == 1) {
that.chooseWxImageShop('camera')
}
} }
})
},
chooseWxImageShop: function (type) {
var that = this;
wx.chooseImage({
sizeType: ['original', 'compressed'],
sourceType: [type],
success: function (res) {
/*上传单张
that.data.orderDetail.shopImage = res.tempFilePaths[0],
that.upload_file(API_URL + 'shop/shopIcon', res.tempFilePaths[0])
*/
// 上传多张(遍历数组,一次传一张)
for (var index in res.tempFilePaths) {
that.upload_file('后台接口地址', res.tempFilePaths[index])
} }
})
},
upload_file: function (url, filePath) {
var that = this;
wx.uploadFile({
url: url,
filePath: filePath,
name: 'imagefile',
header: {
'content-type': 'multipart/form-data'
}, // 设置请求的 header
formData: { 'guid':"procomment" }, // HTTP 请求中其他额外的 form data
success: function (res) {
console.log(JSON.parse(res.data).msg)
},
fail: function (res) {
}
})
}
 
后台代码
public String doUpload(HttpServletRequest request, HttpServletResponse response,
@RequestParam(value = "imagefile", required = false) MultipartFile imagefile)
throws Exception { try { String type = imagefile.getOriginalFilename().substring(imagefile.getOriginalFilename().lastIndexOf(".")).toLowerCase();
File targetFile = new File("D:/images/upload/" , type);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
imagefile.transferTo(targetFile);
return type
} catch (Exception e) { return "上传失败"
}

微信小程序图片上传java后台(前后端代码)的更多相关文章

  1. 微信小程序图片上传放大预览删除代码

    效果: 一,下面是上传图片的效果 image.js代码: Page({ //选择相册或拍照 data: { imgs: [] }, //上传图片 chooseImg: function (e) { v ...

  2. 微信小程序图片上传和裁剪

    本篇博客用于解决微信小程序图片裁剪问题 图片裁剪常用于头像选择和图片合成等. 图片裁剪解决方案: 目前网络上知名的微信小程序图片裁剪插件是we-cropper(文末有链接) 操作步骤:下载好we-cr ...

  3. 5行代码实现微信小程序图片上传与腾讯免费5G存储空间的使用

    本文介绍了如何在微信小程序开发中使用腾讯官方提供的云开发功能快速实现图片的上传与存储,以及介绍云开发的 5G 存储空间的基本使用方法,这将大大提高微信小程序的开发效率,同时也是微信小程序系列教程的视频 ...

  4. 快速高效实现微信小程序图片上传与腾讯免费5G存储空间的使用

    本文介绍了如何在微信小程序开发中使用腾讯官方提供的云开发功能快速实现图片的上传与存储,以及介绍云开发的 5G 存储空间的基本使用方法,这将大大提高微信小程序的开发效率 对于一般的图片上传功能开发,我们 ...

  5. 微信小程序图片上传并展示

    1.首先编写微信小程序的页面和样式: index.js var total = []; Page({ data: { perImgSrc: [] }, onLoad: function (option ...

  6. 微信小程序---图片上传+服务端接受

    原文地址:http://blog.csdn.net/sk719887916/article/details/54312573 微信小程序,图片上传,应用地方-修改用户信息的头像. 详细代码: 小程序的 ...

  7. 微信小程序图片上传

    uploadImage : function (){ wx.chooseImage({ count: 9, // 默认9 sizeType: ['original', 'compressed'], / ...

  8. (SSM框架)实现小程序图片上传(配小程序源码)

    阅读本文约"2分钟" 又是一个开源小组件啦! 因为刚好做到这个小功能,所以就整理了一下,针对微信小程序的图片(文件)上传! 原业务是针对用户反馈的图片上传.(没错,本次还提供小程序 ...

  9. 小程序--->小程序图片上传阿里OSS使用方法

    小程序图片上传阿里OSS使用方法 首先看下参考文档 ( http://blog.csdn.net/qq_38125123/article/details/73870667) 这里只将一些运用过程中遇到 ...

随机推荐

  1. BZOJ1143:祭祀river(二分图求有向图的最大点独立集)

    在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都 会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成的网络.每条河道连接着 ...

  2. 从0开始学习Hadoop(2)安装JDK

    参考文档: 安装包方式安装:http://www.cnblogs.com/wuyudong/p/ubuntu-jdk8.html PPA方式安装:推荐  http://www.cnblogs.com/ ...

  3. Pascal之工种问题

    program Project2; Type ma=(A,B,C); wk=..; const x:array[ma,wk] of integer =((,,),(,,),(,,)); var max ...

  4. Extjs 3 Grid相关操作

    extjs gridpanel 操作行 得到选中行的列   var model = grid.getSelectionModel();   model.selectAll(); //选择所有行 mod ...

  5. Spring Boot:关于“No converter found for return value of type: class xxx”的解决方法

    首先在对应的controller中的@RestController中返回json对象的操作 public class HelloController { @RequestMapping("/ ...

  6. jQuery笔记之事件绑定

    .on(),off(),.one(),.trigger() .hover() jQuery实例方法-动画 .show(),.hide(),.toggle() 参数:null或(duration,eas ...

  7. 无法生成DH密钥对Could not generate DH keypair

      Source from here Add this library to classpath(following is maven project) <dependency> < ...

  8. Django中的cookie和session实现

    cookie from django.shortcuts import render, HttpResponse, redirect # 此装饰器的作用就是讲所有没有cookie验证的页面都需要验证后 ...

  9. Python函数缓存

    函数缓存 (Function caching) 函数缓存允许我们将一个函数对于给定参数的返回值缓存起来.当一个I/O密集的函数被频繁使用相同的参数调用的时候,函数缓存可以节约时间.在Python 3. ...

  10. _bzoj1088 [SCOI2005]扫雷Mine【dp】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1088 简单的状压dp(话说本题的编号减1,即1087,也是一道状压dp),不解释. #inc ...