Download File via HTTP

tomahawk1

New Member
Hi, how to download file using HTTP Request? The end point responds with file which is only loaded to text data item. If I change "File URL" to True,
it expects me to provide in "Body" the path to file when POSTing (uploading) via HTTP, I think. But I'd like to download file instead.
 

Attachments

  • http file.png
    http file.png
    23.2 KB · Views: 25

sahil_raina_91

Active Member
Hi, how to download file using HTTP Request? The end point responds with file which is only loaded to text data item. If I change "File URL" to True,
it expects me to provide in "Body" the path to file when POSTing (uploading) via HTTP, I think. But I'd like to download file instead.
The API clearly requires a Body for you to be able to directly download the file. Without relevant details like address, body and header information, there is only so much one can help you with.

Easier way out is to : Paste the contents of the text data item in the file.
 

Rich

Member
What format is the response you get back from the endpoint?

Is it just raw text that you want to save as a .txt file? If so you can use the utility action to write it to a file to save it down.

Using the 'file url' input is only relevant when sending a file to the API, not for a GET request.
 

tomahawk1

New Member
@sahil_raina_91 Thanks, but body is not required. It's a GET request which I tested in Postman. Response is not text but file so content of text data item is gibberish.

@Rich Hi, these are response content headers: 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'Content-Disposition': 'attachment;filename=blabla.xlsx'

I realize I need to use a code stage. I got stuck in turning stream into file:

Code:
Dim request as WebRequest = WebRequest.Create(url)
request.Method = "GET"
request.Headers.Add("Authorization", "Basic " & auth)

Using response as WebResponse = request.GetResponse()
   Dim responseStream as IO.Stream = response.GetResponseStream()
   Dim fs as FileStream = File.Create("C:\downloaded.xlsx")
   fs.Write(responseStream, 0, responseStream.Length)
End Using
 
Top