I need to send a multipart request to server with a file (document_example.pdf) and a json file that contains the data object (data_object_example.json) in Angular 7.
data_object_example.json -> { "attribute1": "name", "attribute2": "second_name" }
I know how create a multipart request, but I don't know how create json file by a object.
Thanks. ;)
Answer: Thanks to HaiTH
const docJson = {
fileDocType: file.name.split('?')[0].split('.').pop(),
fileName: file.name
}
const fileJson = new File([JSON.stringify(docJson)], "file.json", {type: "application/json'"});
const formData = new FormData();
formData.append('json', fileJson);