Hello!
I need to replicate a POST call to send data using multipart/form-data in a HTTPClient.
That should reply the following call:
cURL:
curl --location 'http://elo.local:9090/ix-ELOArchive/plugin/de.elo.ix.plugin.proxy/rest/api/files/5101' \
--header 'Content-Type: multipart/form-data' \
--header 'Authorization: Basic **********' \
--form 'name="Filename.pdf"' \
--form 'maskId="Basic entry"' \
--form 'versionLabel="1"' \
--form 'versionComment="Comment V1"' \
--form 'file=@"/C:/Users/user038/Documents/HiThere.pdf"'
javascript:
// WARNING: For POST requests, body is set to null by browsers.
var data = new FormData();
data.append("name", "Pipponzio.pdf");
data.append("maskId", "Basic entry");
data.append("versionLabel", "1");
data.append("versionComment", "Commento V1");
data.append("file", fileInput.files[0], "/C:/Users/user038/Documents/HiThere.pdf");
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "http://elo.local:9090/ix-ELOArchive/plugin/de.elo.ix.plugin.proxy/rest/api/files/5101");
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.setRequestHeader("Authorization", "Basic ***************");
xhr.send(data);
I use HTTPClient to consume REST API endpoints but never used multipart/form-data.
If someone chan post a tiny complete example would make me really happier :-)
Thanks