i’m currentlly facing a issue for FormData, i try to find a best way to handle the data like below that can be transfer through FormData.
As you can see, i got an object that contains the travel claim details, i have an array that names travels, generally we can have several travels but i try to keep it simple so just put one there. In each of the travel, we have multiple trips and in each of the trip, we have a file list that allow the users to upload the receipts.
The business logic is: i need to make sure the file list needs to belongs it’s trip, when the user view the detail of this claim, they need to know the file list 1 belongs to the trip 1 and the filelist 2 belongs to the trip 2.
For none File data, i know we can use append to append each of the key value into FormData and we can use formData.append(“fileList[]”, each file) to upload the file to the form, but when the files belongs to the nested objects, what we should do?
I have use multiparty in Node.js backend.
Any help will be much appreciate!
{
"code": 202401,
"name": "Travel claim",
"valid_date": [
1732971600000,
1735563600000
],
"status": "Pending",
"total_amount": "100.00",
"expenses": [
{
"index": 0,
"amount": 1,
"discount": 0,
"sub_total": 1,
"EXPENSETYPE_id": 7,
"TRIP_id": 1734073861830,`enter code here`
"key": 1734073875920
},
{
"index": 1,
"amount": 1,
"discount": 0,
"sub_total": 1,
"EXPENSETYPE_id": 7,
"TRIP_id": 1734073865644,
"key": 1734073876603
}
],
"travels": [
{
"index": 0,
"key": 1734073861830,
"name": "Travel",
"trips": [
{ // Trip 1
"index": 0,
"location_from": "1",
"location_to": "2",
"start_date": 1732971600000,
"end_date": 1732971600000,
"key": 1734073861830,
"trip_file_list": [
{ // File object
"status": "ready",
"name": "flight_tickets1.png",
"size": 129789,
"percentage": 0,
"uid": 1734073886202,
"raw": {
"uid": 1734073886202
}
}
]
},
{ // Trip 2
"index": 1,
"location_from": "2",
"location_to": "1",
"start_date": 1735563600000,
"end_date": 1735563600000,
"key": 1734073865644,
"trip_file_list": [
{ // File object
"status": "ready",
"name": "flight_ticket2.pdf",
"size": 582252,
"percentage": 0,
"uid": 1734073890187,
"raw": {
"uid": 1734073890187
}
}
]
}
]
}
]
}