上傳單檔案可以,上傳檔案數組背景無法擷取
背景:
@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 add(@Param("fileList") TempFile[] fileList, @Param("customId") Long customId) {
System.out.println(fileList);
for (TempFile file : fileList) {
System.out.println(file.getName());
}
Map 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('失敗');
});