天天看點

formdata怎麼傳數組_FormData上傳多檔案,背景擷取不到檔案數組,單檔案可以拿到...

上傳單檔案可以,上傳檔案數組背景無法擷取

背景:

@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('失敗');

});