Extract attachment file from REST API JSON Response

Hello All,

I have a REST API which returns the attachment file (.zip file) once I decode API response from base64 to file. To decode manually i am using online decoder like “(https://base64.guru/converter/decode/file)”

The same i need to implement in UiPath studio as well.

I am able to get the response JSON of REST API, now I have to generate the attachment file out of response content id, kindly guide me to achieve same in UiPath.

Is there any activity in UiPath to achieve this requirement ?

Thanks for you response.

Thank you,
Vinay

Hi,

Can you try the following steps?

  1. Get HTTP response body using HTTP Request activity.
  2. Deserialize JSON string to jObject
  3. Extract base64 string of zip file from jObject
  4. Decode base64 string to byte array
  5. Write the byte array to a file.

Regards,

1 Like

@Yoichi - Thanks for the response. Could you please help me with 4th and 5th steps in detail. Till now, I am able to extract the Document Content id from the JSON response.

Please guide me with the below steps -

  • Decode base64 string to byte array
  • Write the byte array to a file.

Thanks,
Vinay

Hi,

Decode base64 string to byte array

Can yo try the following expression?

bytearray = Convert.FromBase64String(base64str)

note: bytearray is byte[] type variable.

Write the byte array to a file.

We can easily write bytearray to file using WriteAllBytes method. The parameter should be set as the following image.

Hope the above helps you.

Regards,

1 Like

@Yoichi Do we need to define WriteAllBytes method somewhere? Please refer the below snippet -

Hi,

I suppose your Parameters property might be incorrect. Can you check it is same as the above image?

Regards,

@Yoichi - I believe we have to define WriteAllBytes method before using it into invoke method. I have created variable with name -bytearray, here is the snippet -

Hi,

Yes, we need to define bytearray as byte[] in advance. It seems good.
Can you share Parameters property window of Invoke Method which calls WriteAllBytes?

Regards,

@Yoichi - Please refer the snippet of Invoke Method property window.

Hi,

Thank you for sharing.

We need to set the values in the order of the arguments.

So, first, set String type variable, next set Byte[] type variable. Can you try?

Regards,

@Yoichi - I am able to extract the attachment file. Thank you so much for your help. Appreciate it.

1 Like

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