简体   繁体   English

Spring Boot使用多个对象上传多个文件

[英]Spring Boot multiple files upload with multiple objects

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 我的POJO课

@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 如何通过邮递员发送对象列表,或者可以像下面的REST控制器那样处理请求

@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 我正在尝试为此打击任务创建API

在此处输入图片说明


I have done this by use of Meta-Data concept there are few changes I did in controller and bean 我已经通过使用元数据概念完成了此操作,我在控制器和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 希望对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM