Answer the question
In order to leave comments, you need to log in
How to send file and JSON data?
There is a task to execute sending of a file and the data.
When sending a file, you must attach a json object.
We create a `FormObj()` and put a file and a JSON object into it.
Technologies used:
- axios
Problem :
Attached object comes to backend as a string: `` I
specify headers when submitting:
`Content-Type': 'multipart/form-data`
`Accept: apllication/json;charset= UTF-8`
Code:
export const importLeads = function(form, delimiter, first_line_poss, selectedColumn, extraField){
let data = {
"options": {
"delimeters": delimiter,
"first_line_poss": first_line_poss
},
"colums": selectedColumn,
"extraComuln": extraField || undefined
}
form.append("data", data)
return api.put(`leads/import/csv`, form,
{
headers:
{
'Content-Type': 'multipart/form-data'
}
})
-----------------------------9246871473245247581210159984
Content-Disposition: form-data; name="file"; filename="somefile.csv"
Content-Type: text/csv
$email,$name,$phone,Property name 1,Property name 2
[email protected],Sasha,89991234567,Property value,Property value
----- -----------------------9246871473245247581210159984
Content-Disposition: form-data; name="data"
[object Object]
-----------------------------9246871473245247581210159984--
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question