function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gv007gv007 

sending a non-ascii file via Http POST

Hello All,

 

I need to send an uploaded document to a third party webservice. I can send text files fine. But all other file types are getting corrupted.

I have been struggling for the past 3 weeks with this problem . I ahve tried several variations like Content-Transfer-Encoding : base64 and sending the

EncodingUtil.base64Encode(blob) with no luck. Is there some thing I am missing. I need to be ableto send pdfs, images, doc files.

Please help.

 

Thanks

Gopi

String response; String boundary = 'AaBbCcX30'; String m_URL = 'some url'; String content = 'Content:\r\n--' + boundary + '\r\nContent-Disposition:form-data;name="' + p_fileName + '";filename="'+p_fileName+'"\r\n'; content +='Content-Type:' + p_fileContentType + ',charset=ISO-8859-1,*,utf-8\r\n'; content +='Content-Transfer-Encoding: binary\r\n\r\n'; content += p_fileBlob +'\r\n\r\n'; content += '--'+boundary+'--\r\n'; System.debug(p_fileBlob.size()+'content ' + content); Http m_http = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint(m_URL); req.setHeader('Content-Type','multipart/form-data;boundary='+boundary); req.setMethod('POST'); req.setBody(content); HttpResponse m_httpResp = null; m_httpResp = m_http.send(req); m_strHttpResp = m_httpResp.getBody();

 

PamSalesforcePamSalesforce

Hi Gopi,

 

Where you able to solve the problem. Can you post the complete working code.

 

Thanks a lot.

modomodo

I am working this same issue as well and have run in to the same problem. My motivation to manually formulate the POST message for the file is that it seems like the only way to associate any server response processing with a file upload. If someone knows of a way to async capture the response after using a standard FORM/submit action that would be helpful as well.

KaziKazi

Hello,

 

Were you able to send a non-ascii file (file size of more than 1MB)  to a third party server successfully? I am having the same difficulty in forming the multipart request with POST and sending a non ascii file of size more than 1MB. I really appreciate if you can share your experience and may be sample code on this.

 

Thanks,

- Murthy

gv007gv007

 

Based on Winter11 release they lifited file size limit (I have to verify the release notice once again).I am not abble to do that non-acsici file.I will post some sample code.

thanks

DeepuDeepu

Hello

 

I need to send a text file using HTTP post.

Could you please share the code .

 

Thanks in advance

 

VarunCVarunC

guys anyone able to solve this? I'm also having trouble with uploading files other than text files to external service. :( .. help

MiddhaMiddha

I am facing the same issue, any success? Can anyone please share the code.

VarunCVarunC

Yes its not possible yet :( ...

EnreecoEnreeco

Hi guys I need some comments over my solution

http://enreeco.blogspot.it/2013/01/salesforce-apex-post-mutipartform-data.html

I've meed up with Blob, Encoding/Decoding and HttpResponse

Tell me what you think!

indyindy

Hi Enreeco,

 

I am currently working on post a document to third party server through http.

I have one small question regarding the final code that posted in your blog.

 

You have declared and initialized the body as body+='Content-Disposition: ....

Where you have used this 'body' variable again. 

 

Do I need to modify the bodyEncoded like the below ?

String bodyEncoded = body+EncodingUtil.base64Encode(file.body);

 

 

Please help me ...I have posted the same question in your blog also.

 

 

Thanks,

Indy.

 

 

Murali Krishna 56Murali Krishna 56
Tons of Thanks @Enreeco