1. Piero Salandin
  2. PowerBuilder
  3. Thursday, 27 July 2023 09:52 AM UTC

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

 

Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Friday, 28 July 2023 10:46 AM UTC
  2. PowerBuilder
  3. # 1

Hi Piero,

You can try the simple example of the HttpClient.PostDataStart method: PostDataStart - - PowerScript Reference (appeon.com)

Regards, Logan

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.