对比io流的文件上传来说 这个MultipartFile才是真正强大的
自己写的比较次勿喷-这个只是为了自己看的
@PostMapping("/upLoadPhoto")
public RestAPi upLoadPhoto(MultipartFile file) throws IOException {
//获取文件后缀
String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1)
.toLowerCase();
// 重构文件名称
String pikId = UUID.randomUUID().toString().replaceAll("-", "");
String newVidoeName = pikId + "." + fileExt;
//保存视频
File fileSave = new File("E:\\new\\CSSystem\\ui\\public\\assets", newVidoeName);
file.transferTo(fileSave);
log.info(fileSave.getPath());
log.info(newVidoeName);
return new RestAPi(1,"上传成功",null);
}
配置文件信息
application.yml
spring:
servlet:
multipart:
max-file-size: 200MB #文件上传大小
max-request-size: 200MB #设置最大请求大小
vue+element 前台
这个只是测试用的
<el-upload
class="avatar-uploader"
action= "./user/upLoadPhoto"
:show-file-list="false">
<!--:on-success="handleAvatarSuccess">-->
<!--:before-upload="beforeAvatarUpload"-->
<img v-if="imageUrl" :src="imageUrl" class="avatar">
<i class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>