上传单文件可以,上传文件数组后台无法获取
后台:
@ApiOperation(value = "新增", nickname = "/file/add", httpMethod = "POST", response = Object.class, notes = "新增", authorizations = {
@Authorization(value = "") })
@ApiImplicitParams({
@ApiImplicitParam(value = "fileList", paramType = "form", name = "fileList", dataType = "java.io.File"),
@ApiImplicitParam(value = "customId", paramType = "form", name = "id", dataType = "Long") })
@At(value = "/file/addComment")
@AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/tmp" })
public Map<String, String> add(@Param("fileList") TempFile[] fileList, @Param("customId") Long customId) {
System.out.println(fileList);
for (TempFile file : fileList) {
System.out.println(file.getName());
}
Map<String, String> map = new HashMap<>();
map.put("result", "test");
return map;
}
前台
let param = new FormData(); //创建form对象
param.append('fileList', fileList);
let config = {
headers: {
'Content-Type': 'multipart/form-data'
}
};
api.upload('/test/api/file/add', param, config, resp => {
console.log(resp);
},
error => {
this.$Message.error('失败');
});