0

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

enter image description here

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

enter image description here

4
  • In the controller annotate rawData method parameter with @RequestParam and in Postman name the file parameteres rawData.file. As a generic hint the request parameters names should match the object structure of the server side objects which will receive the values Commented Dec 14, 2018 at 10:20
  • my question is how to tackle the request of the list objects under the request param. single file upload I know the way. Commented Dec 14, 2018 at 10:23
  • if sending one file is working, then you need to add a property of type List<MultipartFile> in the FileWithObject. Something similar with @JsonProperty("file") private MultipartFile file; but the type should be a collection and the name of @JsonProperty should be something different then file Commented Dec 14, 2018 at 10:28
  • Look at this example:callicoder.com/… Commented Dec 14, 2018 at 10:43

1 Answer 1

2


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

enter image description here enter image description here

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

Sign up to request clarification or add additional context in comments.

1 Comment

full code of all possible file upload with spring github.com/NABEEL-AHMED-JAMIL/file-uploader

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.