0

I want to build a request in insomnia to upload person, documents and it's files How can I put a multipart file inside a JSON object? I don't want to deal with string base64 because it's too big and too slow to travel over the network.

I have a rest api made with spring boot and kotlin that will receive this JSON file.

Here's some code for what I want to achieve:

curl --request POST \
--url http://localhost:8080/ \
--header 'content-type: multipart/form-data; boundary=-- 
-011000010111000001101001' \
--form 'person={
"first_name": "Foo",
"last_name": "Fighters"
}' \
--form 'document=[
 {
  "document_name": "test1",
  "document_description":"test1",
  "document_file": "multipart file1"
 },
 {
  "document_name": "test2",
  "document_description":"test2",
  "document_file": "multipart file2"
 },
 {
  "document_name": "testN",
  "document_description":"testN",
  "document_file": "multipart fileN"
 }   
]'

Where the key document_file value stands for the file itself, not a String. Some pictures to make it clear:

Here is the overview of the multipart overview multiparts

Person detail:

person object

Document detail: document object

I need to know what files are from what documents, and I can have 0 or many documents related to the person. Therefore, that's why adding 1 file for each document I want to create won't work. It needs to be inside the object(just like presented in the images) that way I know that file-X is from document-X and vice-versa.

Thanks in advance!

lat94
  • 511
  • 1
  • 5
  • 18
  • 1
    I think you'd need to store the files somewhere else, and store the unique filename and/or file location in the JSON key. – Pradeep Aug 27 '19 at 04:12
  • and how would I do that? Could you give me an example by answering the question? – lat94 Aug 27 '19 at 12:06
  • What have you done so far? It's easier to understand your needs when some piece of code is already implemented. Do you need to attach additional files located at FileSystem and described by `document_file` key? – Nikolai Shevchenko Aug 27 '19 at 12:22
  • that's all I've done untill now. I've been thinking in different ways to do this. And yes, the file will be in a local path, let's say mobile storage for the example. How would I reference the file inside the object as a value of `document_file`? – lat94 Aug 27 '19 at 12:30

0 Answers0