Spring Boot 使用多个对象上传多个文件 [英] Spring Boot multiple files upload with multiple objects
问题描述
我需要帮助,我上次使用带有对象的单个文件上传创建控制器,它对我有用
我的 POJO 课
@JsonInclude(JsonInclude.Include.NON_NULL)@JsonPropertyOrder({ "文件", "数据" })公共类 FileWithObject{@JsonProperty("文件")私有 MultipartFile 文件;@JsonRawValue@JsonProperty("数据")私人 T 数据;}
<块引用>
我的休息控制器
@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/singleFileUploadWithObject/{folder}",方法 = RequestMethod.POST)@ResponseBody//api 工作公共字符串 singleFileUploadWithObject(@PathVariable(name="bucket-uuid", required = true) 字符串bucketUUId,@PathVariable(name="folder", required = false) 字符串文件夹,FileWithObject rawData) {返回ping响应;}
我的邮递员结果
这对我来说都是有用的.如何通过邮递员发送对象列表,或者可以像下面的rest控制器一样处理这种请求
@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/listOfObjectsWithSingleFile/{folder}", method = RequestMethod.POST)@ResponseBody公共字符串 listOfObjectsWithSingleFile(@PathVariable(name="bucket-uuid", required = true) 字符串bucketUUId,@PathVariable(name="folder", required = false) 字符串文件夹,设置原始数据) {返回ping响应;}
如何处理对象列表
<代码>[{文件":文件对象,数据":zyz"},{文件":文件对象,数据":zyz"}]
<块引用>
我正在尝试为此打击任务创建 api
我通过使用元数据概念来做到这一点,我在控制器和bean
控制器
@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/listOfObjectsWithSingleFile/{folder}",方法 = RequestMethod.POST)@ResponseBody公共字符串 listOfObjectsWithSingleFile(@PathVariable(name="bucket-uuid") 字符串bucketUUId,@PathVariable(name="folder") 字符串文件夹,FileWithObject objects) {//改变这个 SetrawData 到 FileWithObject 对象返回ping响应;}
<块引用>
豆
@JsonInclude(JsonInclude.Include.NON_NULL)@JsonPropertyOrder({ "文件", "文件", "数据" })公共类 FileWithObject{@JsonProperty("文件")私有 MultipartFile 文件;@JsonProperty("文件")私有列表档案;@JsonRawValue@JsonProperty("数据")私人 T 数据;//像(元数据)一样工作列表原始数据;//获取设置器}
<块引用>
请求图片
<块引用>注意:- 我仍在寻找这个问题,以一种打击的方式处理这个问题
@RequestMapping(value="/filestore/{bucketuuid}/appsport.com/listOfObjectsWithSingleFile/{folder}", method = RequestMethod.POST)@ResponseBodypublic String listOfObjectsWithSingleFile(@PathVariable(name="bucket-uuid", required = true) String bucketUUId,@PathVariable(name="folder", required = false) String folder,Set原始数据) {返回ping响应;}
希望对大家有所帮助
I need help I last time create the controller with the single file upload with an object and it's work for me like
My POJO class
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "file", "data" })
public class FileWithObject<T> {
@JsonProperty("file")
private MultipartFile file;
@JsonRawValue
@JsonProperty("data")
private T data;
}
MY REST CONTOLLER
@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/singleFileUploadWithObject/{folder}",
method = RequestMethod.POST)
@ResponseBody
// api work
public String singleFileUploadWithObject(
@PathVariable(name="bucket-uuid", required = true) String bucketUUId,
@PathVariable(name="folder", required = false) String folder,
FileWithObject rawData) {
return pingResponse;
}
My Postman result
That's all work for me. How to send the list of the objects through the postman or is possible to handle that way request like below rest controller
@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/listOfObjectsWithSingleFile/{folder}", method = RequestMethod.POST)
@ResponseBody
public String listOfObjectsWithSingleFile(
@PathVariable(name="bucket-uuid", required = true) String bucketUUId,
@PathVariable(name="folder", required = false) String folder,
Set<FileWithObject> rawData) {
return pingResponse;
}
How to handle list of objects
[{
"file": fileobject,
"data": "zyz"
},{
"file": fileobject,
"data": "zyz"
}]
I'm trying to creating the api for this blow task
I have done this by use of Meta-Data concept there are few changes I did in controller and bean
Controller
@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/listOfObjectsWithSingleFile/{folder}",
method = RequestMethod.POST)
@ResponseBody
public String listOfObjectsWithSingleFile(
@PathVariable(name="bucket-uuid") String bucketUUId, @PathVariable(name="folder") String folder,
FileWithObject objects) { // change this Set<FileWithObject> rawData to FileWithObject objects
return pingResponse;
}
Bean
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "file", "files", "data" })
public class FileWithObject<T> {
@JsonProperty("file")
private MultipartFile file;
@JsonProperty("files")
private List<MultipartFile> files;
@JsonRawValue
@JsonProperty("data")
private T data;
// work like (meta-data)
List<FileWithObject> rawData;
// getter setter
}
Image's For Request
Note:- I'm Still looking for this issue handle this in a blow way
@RequestMapping(value="/filestore/{bucketuuid}/appsport.com/listOfObjectsWithSingleFile/{folder}", method = RequestMethod.POST)
@ResponseBody
public String listOfObjectsWithSingleFile(@PathVariable(name="bucket-uuid", required = true) String bucketUUId,
@PathVariable(name="folder", required = false) String folder,Set<FileWithObject> rawData) {
return pingResponse;
}
hope it helps some one
这篇关于Spring Boot 使用多个对象上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!