Http Request Header (Uploading Files)

Hi @barryrodick

I’ve already done something like this before…

I tried exhaustively using HTTP Client activity, and always I got HTTP success status but the file wasn’t submitted.

Then, I decided to implement in a different way, using invoke code activity.

Here you go the solution:

First, add RestSharp dependence to your project

After that, import RestSharp

Then, add an invoke code activity

image

Finally, add the following code (make changes as necessary):

    Dim client As RestClient = New RestClient("https://example.com/api/v2/uploads.json?filename=test.png")
    client.Timeout = 10000
    Dim request As RestRequest= New RestRequest(Method.POST)
    request.AddHeader("Content-Type", "image/png")
    request.AddParameter("image/png", File.ReadAllBytes("C:\Users\gustavo.cervelin\Downloads\test.png"), ParameterType.RequestBody)
    Dim response As IRestResponse = client.Execute(request)
    Console.WriteLine(response.Content)

IMPORTANT NOTES:

  1. At line four, set the content type according your file extension;
  2. The same for line five

That’s it!

If you need help to work with the response, let me know

2 Likes