0

I am trying to post a json formatted file and csv formatted file using a curl command.
Here is my spring boot endpoint:

@PostMapping
public MyDTO registerMyEntity(
        @RequestBody MyDTO myDTO ,
        @RequestParam("file") MultipartFile file) {...}

My json file myJsonFile.json contains this:

{
        "key1": "value1",
        "key2": "key2"
}

and my csv file myCSVFile contains this:

key3;key4
value3;value4

I used this curl (after having tried many many many ones):

curl -X POST -H 'Content-Type: multipart/form-data' -d @./import.json -F 'file=@./import.csv;text/csv' http://localhost:8080/path/to/endpoint

but no way... Any suggestions ?

1
  • Could you please post the response, that you get after executing the curl command? Commented May 31, 2022 at 13:23

1 Answer 1

1

I found the answer:

curl --location --request POST 'http://ip:port/url/to/endpoint' \
--form 'dataSetCourses=@"path/to/csv/file"' \
--form 'newDataSet=@"path/to/json/file"'

Where the endpoint has been modified as follow:

@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
    public MyDTO registerMyEntity(@RequestPart MyDto newDataSet,
            @RequestPart MultipartFile dataSetCourses) {...}
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.