HTTP Request POST image issue

Hi all,

I have a problem making a POST call to “Contentful” API for uploading an image and I am hoping that you can point me in the right direction. I searched the forum and found the following topic which seems to be pretty close to what I want to do, so I tried to adapt this to my case.

The call I am trying to perform looks like this and the image needs to be sent in binary format.

Please find the steps I my workflow and let me know if you notice anything wrong.

  1. I set a variable (InputFile) with the full path to my image file
  2. Then I read the bytes using another assignment activity - FileBytes = File.ReadAllBytes(InputFile)
  3. As the HTTP Request body does not accept an Array of Bytes (Bytes) I convert the “FileBytes” to Base64String - FileBitString = Convert.ToBase64String(FileBytes).
  4. Just to confirm that the bytes are read correctly I set the following VB Code in Invoke Code to generate the image at another location - File.WriteAllBytes(OutputFile, Convert.FromBase64String(FileBase64String)). I can confirm that the conversion works as expected.

  1. As an additional step I am also outputting the Base64String to a .“bin” file as I tried to attach it to the HTTP Request action, but this should not be necessary.
  2. This is what my HTTP Request looks like where I passed the Base64String variable in the Body and changed the format to “application/binary”.

When I run the workflow without attaching any file it gives me the following error:

image

Therefore I also tried to attach the image file as well as the “.bin” file which contains the base64 string. Then I get this error:

image

I have also tried to pass the Base64 as a parameter, but didn’t work.

I appreciate your help :slight_smile:

1 Like

I am using version WebApi package - 1.21.0

You can explore the details what is done by POSTMAN when checking the POSTMAN Console

With this output it can be rated if the call can be done with the HTTP Request activity (due there can be some limitations which will restrict the usage)

As an alternate HTTPClient custom call can be checked as it can be an alternate

1 Like

Hi,

Unfortunately, I have limited permissions on my work machine and cannot install POSTMAN, but will look for some alternative.

In the meantime, would you be able to provide me with an example of how the HTTPClint can be used in UiPath to send a file via an API call as this is not something I have ever tried/used before? Thanks

we would suggest waiting for the details, that you will gain from Postman

In general, the link to the HTTPClient docu lists down the capabilities

It depends on the API you are consuming. In previous experiences I’ve uploaded files using the File Attachments (Multipart Form Data requests) or by including the encoded content of the file as a field in a json body. This case is another option. Let me try it and I’ll get back to you with more clarity

@VasilD I am not able to test this specific API right now. But I’d try something like this

Apart from this setting, add the required Headers

Hi @dokumentor,

I have tried to attach the image file path as data-binary and also to pass the base64 string in the body, but it didn’t work. I also tried to remove the body completely and just use the attached image as I read that Postman automatically converts images to BASE64 if the “form-data” option is used in the body.

image

Unfortunately, this didn’t work either.
Below you can find a link to the API documentation if you have any other ideas:

Many thanks

@VasilD
had you tried?

UPD1 - hint on Package referencing:

Try this way. I’ve just tried and received a succesful response:


image

Hope it helps!

1 Like

Hi,

Thanks. I have tried again with the suggested setup, but I am still facing the below error:

I am not quite sure why is not recognizing the “Content-Type” header. I also set the file as an attachment as per the screenshot below:

image

Would you be able to advise what version of the UiPath WebAPI activities you are using as it may be a bug in v 1.21.0? Thanks

There is a difference between your setup and mine in the way the content is handled. Check the property Body (as setup in the image)

In my last test I didn’t use the Attachments section of the activity

Activity Package used is the same v1.21.0
The image shows a notification for the "UiPath.WebAPI.Activities" version 1.21.0 package, indicating that it requires Studio 22.10.5 or higher, with a warning that some functionality may be missing on lower versions. (Captioned by AI)

Hi Gabriel,

Thank you for all your help.

Before creating my previous post I already updated the body to what you suggested:

However, if I remove the attached image it just returns “The resource is not found” as per the screenshot below:

image

I have performed several GET calls so I am sure that my space and environment IDs are correct. I also tested uploading an image through the GUI and it works fine, so I am not sure if there is anything that needs to be enabled on the Contentful side so I can use the upload API?

I also tried to retrieve an asset using the below call, but it can’t find the file I am looking for:

I took the asset ID through the Contentful GUI > Media > Pick and Item > Info section.
Would you be able to check if this works for you? If it does then the problem should be with my account as I also tested the calls through PowerShell and the results are exactly the same.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.