使⽤PostMan测试⽂件上传接⼝
1.header,由于没有登录不能访问,要传⼀个token
2.body,见图
@ApiOperation(value = "上传⾝份图⽚返回上传后⽂件名")
@PostMapping(value = "/uploadImgFile", headers = "content-type=multipart/form-data")
public ErrorObject uploadImgFile(@RequestParam("file") List<MultipartFile> files, HttpServletResponse response) throws Exception {
ErrorObject error = new ErrorObject();
for (MultipartFile file : files) {
Map<String, Object> map = new HashMap<>();
String ext = StringUtils.OriginalFilename(), ".");
if ("exe".equalsIgnoreCase(ext) || "bat".equalsIgnoreCase(ext)) {
error.setMsg("禁⽌上传的⽂件格式");
error.setSuccess(false);
return error;
}
try {
File folder = new File(saveFilePath + "\\");
if (!ists()) {
folder.mkdirs();
}
String fileName = UUID.randomUUID() + "." + StringUtils.OriginalFilename(), ".");
String filePath = saveFilePath + "\\" + fileName;
log.debug(filePath);
String[] arrayStr = fileName.split("\\.");
map.put("url", "/upload/viewImg/" + arrayStr[1] + "/" + arrayStr[0]);
map.put("fileName", fileName);
error.setSuccess(true);
error.setMsg("上传成功");
error.setMap(map);
getsavefilename} catch (Exception e) {
<("{}", e);
error.setMsg("上传失败!" + e.getMessage());
error.setSuccess(false);
return error;
}
}
return error;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论