Situation
Currently, I'm dealing with a page comprising questions structured as shown below:
sections:[{
section: 1,
questions:[{
question: 1,
attachment: [FormData Object]
...
},
{
question: 2,
attachment: [FormData Object]
...
}]
}, ...]
Each question is associated with an attachment. To handle this, I've utilized a FormData
object to upload the file and link it with the question object. For instance:
let formData = new FormData();
formData.append('file', event.target.files[0])
question.attachment = formData
Everything seems to be in order at this stage. However, issues arise when attempting to send this data to the server. When utilizing the following code for sending it:
this.$http.post('my-path', {data: this.sections}, {headers: {'Content-Type': 'multipart/form-data'}, emulateJSON: true})
Despite using emulateJSON: true
, the request is successful but the attachment
attribute is not included in the request.
Moreover, specifying
headers: {'Content-Type': 'multipart/form-data'}
results in sending a null request for unknown reasons.
Is there a viable solution to effectively accomplish this task?