HttpRequest upload file

Hi community,

I am trying to sent this PUT request to upload a file.
I am not sure how to translate this Body/binary into Studio’s Body.

Would you have any suggestion?
There is a very good tutorial here: HTTP REQUEST - POST - UNRECOGNIZED UPLOADED FILE - #6 by Cristian_Negulescu. Thank you @Cristian_Negulescu! but probably my API architecture is different than what is shown.
On HttpRequest documentation (HTTP Request) are not many details.

Thank you for any thoughts.
Regards,
Coty

PS: I hope the same subject wasn’t explained somewhere else. I haven’t found on Forum

Hi,

I already faced this issue. The solution was to convert the body of the file into a base64 variable and put it inside the body. But it was a POST request. So maybe you need to convert the file before trying to upload it.

Good luck

Hello Coty,
To solve this issue I write VB.NET code and invoke code all the code you will find in the description of the videos:

Thanks,
Cristian

Hi Melanie,
Thanks for your reply. Would that work for 600 MB .zip files?
Regards,

Hi Cristian,
Thank you for your tutorials and ideas. Same question, would that work for 600 MB .zip files?
Regards,
Coty

I never tested. Is VB.NET code I don’t know how to go lower in UiPath Studio.

Hi Cristian,
I am trying the C# bit. I have two more questions:
Any idea why do I get this error:
“Main.xaml: No compiled code to run
error CS4033: The ‘await’ operator can only be used within an async method. Consider marking this method with the ‘async’ modifier and changing its return type to ‘Task’. At line 11
error CS4033: The ‘await’ operator can only be used within an async method. Consider marking this method with the ‘async’ modifier and changing its return type to ‘Task’. At line 13”

And:
my file is uploaded in Postman, using the Body/binary method. How this should be changed in the MultipartFormDataContent?

Thank you again for your support and for the tutorials.
Coty

Hello Coty,
Try to avoid Await because you need Async I don’t know how to use this UiPath Studio. In Visual Studio you can do this but here I don’t know.
Try to use RestSharp instead of default HTTPrequest
https://restsharp.dev/usage/files.html

Thanks,
Cristian

Hi , did you find any solution ? Does UiPath still not support binary files upload ? @MVP2022 @Forum_Staff

Hello,

Please try below C Sharp Code and add this in your invoke code activity.

Byte[ ] fileBytes = File.ReadAllBytes(in_strFilePath);

RestSharp.RestClient client = new RestSharp.RestClient(in_strEndpoint);
RestSharp.RestRequest request = new RestSharp.RestRequest(RestSharp.Method.POST);

request.AddHeader("<<Put Your Header Key>>", in_strDocumentName);
request.AddHeader("<<Put Your Header Key>>, in_strAPIKey);
request.AddHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

// Add the file content as bytes to the request body
request.AddParameter("application/octet-stream", fileBytes, RestSharp.ParameterType.RequestBody);

// Execute the request
RestSharp.IRestResponse response = client.Execute(request);
Console.WriteLine("Response Status Code: " + response.StatusCode.ToString());
1 Like