0

I want to write api using Spring boot Multipart file upload as part of json body and also want to save img url in database. Requests that look like this:

------WebKitFormBoundarynBsAcX7rJhOGsmfY
Content-Disposition: form-data; name="fdata"; filename="blob"
Content-Type: application/json

{"firstname":"saurabh","lastname":"mishra","mobile":"943847557"}
------WebKitFormBoundarynBsAcX7rJhOGsmfY
Content-Disposition: form-data; name="files"; filename="download.jpg"
Content-Type: image/jpeg


------WebKitFormBoundarynBsAcX7rJhOGsmfY--

Please help me to find the solution.

1
  • 1) Format your code using the {} formatter while posting. 2) Include your own attempts for solving the issue and where you are getting struck Commented Jul 19, 2018 at 6:36

1 Answer 1

1

I solve this issue in this way.

My API Method

@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/singleFileUploadWithObject/{folder}",
        method = RequestMethod.POST)
@ResponseBody
public String singleFileUploadWithObject(
        @PathVariable(name="bucket-uuid", required = true) String bucketUUId,
        @PathVariable(name="folder", required = false) String folder,
        FileWithObject rawData) {
    return pingResponse;
}

My FileWithObject DTO

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "file", "files", "data" })
public class FileWithObject<T> {

    @JsonProperty("file")
    private MultipartFile file;
    @JsonProperty("files")
    private MultipartFile[] files;
    @JsonRawValue
    @JsonProperty("data")
    private T data;
    // getter/setter and other...
}

Note:- For data parameter you can use the mapping process in the singleFileUploadWithObject method hope it's help you and other

enter image description here

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

Comments

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.