How to upload pdf files in binary format using HTTP request and MTOM

Is MTOM (Message Transmission Optimization Mechanism) supported in HTTP reguest i UiPath for sending attachments in binary format?

I need this for sending files > 70 MB. The use of base64 encoding is working fine with smaller files.

I am able to upload a pdf file using MTOM in SoapUI, but struggle to set this up in UiPath.

In UiPath I have these properties for the HTTP Request:
- Timeout (milliseconds) 240000
- BodyFormat application/xop+xml
- Attachments
- File In String “C:\DATA\SOAP prosjekt\07-1050_Dok92.pdf”
- Header
- Content-Type In String “multipart/related; charset=utf-8; type=application/xop+xml; start=rootpart@soapui.org; start-info=text/xml”
- Parameters
Not using any parameters

Are there any parameter that can be used to enable MTOM?

In UiPath the attachment is not sent in binary format, but as an octet-stream.

Here is at comparison from Fiddler from POST done in UiPath og SoapUI:

2 Likes

Hey @Torleif_Arnesen

I guess the issue here is the binary conversion happens at the backend in the Fiddler automatically.

But in UiPath you will need to convert and transform the file before you pass it to the request activity.

Thanks
#nK

Hello @Torleif_Arnesen
Did you manage the way how to send PUT request with binary files?
It does not work for me with ‘Attachments’ property of HTTP PUT Request in Studio.
I have also tried firstly convert the PDF file in ‘assign’ - Convert.ToBase64String(File.ReadAllBytes(“C:\SampleDirectory\TEST.pdf”)) and then pass the value as a body of the request. In this way, it can be sent, but the format is not correctly passed to the END point. - File is corrupted.

Cheers
Emil

@emil.kozub hi , am facing the same issue where the file is uploaded but corrupted ? have u solved this ?

thanks

Hi @Hesham_Conber,
Yes, I managed it with Invoke Code instead of UiPath activities, as there was no working one for my case.
Csharp code used for HTTP PUT request with .PDF file as binary:
As an Arguments I used:
image

Code below:

requestStatus = string.Empty;
resultData = string.Empty;
var resultHeadersJson = String.Empty;
var request = WebRequest.Create(addressUrl);

request.Method = “PUT”;
request.ContentType = “application/pdf”;
var httpRequest = request as HttpWebRequest;
if (!(httpRequest is null))
{
httpRequest.Accept = “/”;
}
var bytes = System.IO.File.ReadAllBytes(filepath);
var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);

try
{
using (var response = request.GetResponse())
using (var responseStream = response.GetResponseStream())
using (var streamReader = new System.IO.StreamReader(responseStream))
{
resultData = streamReader.ReadToEnd();
var httpResponse = response as HttpWebResponse;
requestStatus = httpResponse.StatusCode.ToString();
}
}
catch (WebException webException)
{
using (var response = webException.Response)
using (var responseStream = response.GetResponseStream())
using (var streamReader = new System.IO.StreamReader(responseStream))
{
resultData += streamReader.ReadToEnd();
}
}