YoussefEhab
5 years agoContributor
Upload file using http.client.request
Hello,
How can I upload a file by making a POST request through http.client.request("")
In other words, how can I set the request body with form data as my API is expecting multipart/form-data MIME type.
In JavaScript I do it like this:
var files = document.getElementById("file-input").files;
var formData = new FormData();
formData.append('"file",files[0]);
$.ajax({
url : '${endpoint_url}',
type : 'POST',
data : formData,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success : function(data) {
console.log(JSON.stringify(data));
}
});
Thank you for your help in advance,
Youssef