cancel
Showing results for 
Search instead for 
Did you mean: 

How to download a file using web api.

AZ
Level 3
I want to download a file using Web API. After making request we are getting File data as text in the response content data item.

For your reference I am getting the response as below as text type.

%PDF-1.4 %����
68 0 obj <</Linearized 1/L 1850803/O 70/E 262535/N 13/T 1849323/H [ 916 320]>> endobj
xref
68 31
0000000016 00000 n
0000001236 00000 n
0000001456 00000 n
0000001821 00000 n
0000001957 00000 n
0000002087 00000 n
0000002229 00000 n
0000002972 00000 n
0000003602 00000 n
0000004428 00000 n
0000005000 00000 n
0000005715 00000 n

I am not adding all the content here.

How can we save this content as a original file.

Please help, its an urgent.

Thanks
K

------------------------------
A Z
------------------------------
9 REPLIES 9

Hi, K,

you are gonna get the response in Response Content data item. Then you can use Utility - File Management and Write Binary Action to write this data item into a file. If you are lucky then your stream is correctly saved as PDF file.

Regards,

------------------------------
Zdeněk Kabátek
Head of Professional Services
NEOOPS
http://www.neoops.com/
Europe/Prague
------------------------------

Thanks for reply.

Response content is text type, how can we write text to binary.

Thanks,
K

------------------------------
A Z
------------------------------

Hi A Z,

Is this resolved, if yes can you please let me know how, I am facing a similar issue.

------------------------------
Manish Rawat
Project Manager
Mercer
New Delhi
------------------------------

Hi @Manish Rawat,

The issue here is that the Web API feature doesn't return the raw stream when the response data is a binary stream. Instead, it converts it to text. When that happens there are a few bytes that are lost, as I recall. Because of this, simply writing the text-based Response Content value to disk doesn't work.

What I would suggest is that you use the Utility - HTTP VBO for whatever action it is that you're trying to retrieve the file with. To be clear, if the file were a straight TXT file, the Web API feature would work fine. It's only with binary files (ex. PDF, Zip, etc) that you run into this issue.

Cheers,


------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hi @ewilson,

Thanks for your response. The problem with Utility - HTTP VBO remains the same as the output of both the VBO and Interface provides Result in Text only.
23880.png
Will there be a way to download binary files in any way with BP?

------------------------------
Manish Rawat
Project Manager
Mercer
New Delhi
------------------------------

@Manish Rawat,

There was an update to the HTTP VBO a while back that introduced an action called HTTP Request File.​ This action takes a filename and path as input so that it can write the raw file out to disk after it's been downloaded.

https://digitalexchange.blueprism.com/dx/entry/3439/solution/utility---http

Cheers,

------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hi @ewilson,

I was able to save the files with the updated HTTP VBO and it worked fine.

Thanks for your help!!​

------------------------------
Manish Rawat
Project Manager
Mercer
New Delhi
------------------------------

Hello Eric,

I appreciate your feedback.

I have come across the same situation where I am receiving a binary response for a PDF file as text via Web Api and I need to download/store this pdf in local system. Following your advice, I attempted to resolve the issue, but I encountered an error. Interestingly, I received a binary response in Postman and a binary as text response in WEB API using the same input configuration, indicating that there is no authentication issue. I have included screenshots for your reference.

I would greatly appreciate your assistance and guidance in resolving this issue.

23885.png

23886.png



------------------------------
Amrutha Sivarajan
------------------------------

@Amrutha Sivarajan

An HTTP 500 is a server side error. So there's something about your request that the server doesn't like. It doesn't look like you're including anything in the way of custom headers using the Headers input Collection or setting the Accept header value. If you're able to make this work in Postman, you should check the Postman console to see what the raw request looks like that Postman is sending. You should be able to see any specific HTTP headers that are being set and determine if you need to include those in your request.

Cheers,   



------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------