Do ACC API support multipart/form-data creation? | Community
Skip to main content
September 9, 2022
Solved

Do ACC API support multipart/form-data creation?

  • September 9, 2022
  • 2 replies
  • 1847 views

Hello Expert,

I'm developing the javascript to call the Web-service. However, they require the media-type as 'multipart/form-data'.

I've checked this link about ACC API -> https://experienceleague.adobe.com/developer/campaign-api/api/p-8.html

But it's look like, ACC don't have any class that support to create multipart/form-data

I'm not sure that Adobe Campaign Classic v7 can form this type of data? Or can we import the form-data library into ACC -> How to?

Please help.

Thank you.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Tobias_Lohmann

Hi,

I'm not sure I'm getting what you're trying to achieve. Do you want to call a remote webservice with ACC and that remote webservice requires multipart/form-data?

In Campaign you can use the HttpClientRequest class to construct your http call (including the Content-Type header as multipart/form-data) and send it to the webservice: https://experienceleague.adobe.com/developer/campaign-api/api/c-HttpClientRequest.html?hl=httpclientrequest 

Best regards, Tobias

2 replies

Tobias_Lohmann
Adobe Employee
Tobias_LohmannAdobe EmployeeAccepted solution
Adobe Employee
September 9, 2022

Hi,

I'm not sure I'm getting what you're trying to achieve. Do you want to call a remote webservice with ACC and that remote webservice requires multipart/form-data?

In Campaign you can use the HttpClientRequest class to construct your http call (including the Content-Type header as multipart/form-data) and send it to the webservice: https://experienceleague.adobe.com/developer/campaign-api/api/c-HttpClientRequest.html?hl=httpclientrequest 

Best regards, Tobias

September 12, 2022

Hi Tobias,

Thanks for the response.

Yes, I'm trying to use ACC to call a remote webservice which required multipart/form-data.

And yes, I can use HttpClientRequest with header-type as multipart/form-data.

 

However, I'm stuck at attach the upload file.

The webservice require to upload the file as string(binary) which I have found many posts that using FileReader.readAsBinaryString() but look like that Adobe did not support this class.

 

So, I'm not sure that do we have any other choices that I can do?

PS: If you have an example, please put it in the post.

Thank you 🙂

New Member
December 19, 2024

Hi. I managed to solve the problem using the js below.  In my circumstance I was trying to transfer a very simple csv file with a single column with column header that I had already exported to the Adobe server in the previous step.

 

logInfo("File name is: " + vars.filename)
memBuf = new MemoryBuffer()
memBuf.load(vars.filename)
data = memBuf.toString()
logInfo("Size is " + memBuf.size)

boundary = "nVenJ7H4puv"

body = "--" + boundary + '\r\n'
body = body + "Content-Disposition: form-data; name='upFile'; \r\n"
body = body + "Content-Type: text/csv\r\n\r\n" //two carriage returns required before adding the data
body = body + data + '\r\n'
body = body + "--" + boundary + "--\r\n"

 

url ="https://<url of site> "

var http=new HttpClientRequest(url);
http.header ["Content-Type"] = "multipart/form-data; boundary=" + boundary;
http.header ["Accept"] = "*/*";
http.header ["Authorization"] = "whatever";
http.method = "POST" ;
http.body = body;

http.execute();
var result = http.response.body.toString();
logInfo("Result String: "+result);
var responseCode = http.response.code
logInfo("Response code is: "+ responseCode)