项目的框架是springCloud 的一个服务,图片上传实际上就是用java的IO 流进行读写文件,给后台传递一个路径,后台通过浏览器链接到前端,将前端的图片数据拷贝的服务器的存储地址。
1. 服务端保存图片的地址:
application.yml 文件中添加如下配置:
img:
location: E:\hjy\workspace\wx-back-web\src\main\webapp\olimg\
2、有关文件上传实现
.Controller 中获取路径的
import org.springframework.beans.factory.annotation.Value;
@Value("${img.location}")
private String location;
Controller 中的方法:
import org.springframework.web.bind.annotation.PathVariable;
@RequestMapping("/uploadImg/{imgType}")
public String uploadImg(
@RequestParam("ediormd-image-file") MultipartFile[] files,@PathVariable("imgType") String imgType) {
ResponseData res = new ResponseData();
List proPicList = new ArrayList ();
String filePath = location +