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.
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?
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
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());