219
Views
3
Comments
Solved
API returns a filestream, how do I access that in Outsystems for a download window
Question
Application Type
Reactive

I have an API that returns a filestream, which is an Excel file.  I want to know how to "catch/access" that file so that I can open a windows, Save As, Download file, popup and the user can then save the file.  


In Postman, when you send the API request and look at the response, in the body, it is gibberish.  But when you click on Save Response, it recognizes the file, opens a window to save the file and you click save.  

Hope that is clear enough.

UserImage.jpg
Bryan Richter
Solution

The solution here is to have the API output the file as Base64String.  OutSystems then recognizes the response and sets it to "Text".  You then use an "Assign" to set the output of the API to:

Base64ToBinary(API.Output) 

Then you can pass the file as "Binary Data" to the "Download" Client side action.  You have to provide a name for the file, with extension (myfile.xlsx).

This does not open a save dialog, but it does go right to the downloads folder.

UserImage.jpg
Saurabh Shivananda Prabhu Chimulkar

Hi Bryan,

If the output of the file is binary data, then you can use the Download Element available for Screen Action to get the file downloaded.

Below is a reference: 

https://success.outsystems.com/Documentation/11/Developing_an_Application/Use_Data/Download_a_file_through_browser

UserImage.jpg
Bryan Richter

Here is how the response looks in Postman, note that the body does not have anything to latch onto in this "response".

but when I click on Save Response>Save to File, I go right to a Save Dialog

I need to reproduce this in OutSystems so that when the file stream comes back we go to a Save Dialog.

UserImage.jpg
Bryan Richter
Solution

The solution here is to have the API output the file as Base64String.  OutSystems then recognizes the response and sets it to "Text".  You then use an "Assign" to set the output of the API to:

Base64ToBinary(API.Output) 

Then you can pass the file as "Binary Data" to the "Download" Client side action.  You have to provide a name for the file, with extension (myfile.xlsx).

This does not open a save dialog, but it does go right to the downloads folder.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.