I am trying to download a file using an API request, however the file is not being downloaded, so is this currently possible in wappler?
I have tried using a server connect api, and an app connect api request, using both methods I am getting a 200 OK response, with data like the one below and the file is not being downloaded.
I also tried adding the api request directly as a dmx-bind href and it worked instantly, but I can’t go with that because the api request needs to be secured with an authorization token and I don’t think I can pass that from a url call.
I have the authorization token saved as a cookie when the user logs in, and I pass that to the api request as a header with Authorization, like this:
If it is possible to pass the Authorization that is under Headers directly from the url, then I can continue with the dmx-bind href option, but I don’t know how to do that
Server Connect always returns his data as json. You can try to use the Response step to output the API response directly. At this moment the Response is very limited, it doesn’t allow you to set headers or content type, so can’t promise it will work. Set the Text option to the output of the API {{api1}}. On the client-side use the Server Connect url on a link and add the download attribute to it, you can also set a filename there. https://www.w3schools.com/tags/att_a_download.asp
This should at least work with text based files, not sure if it works with binary files.
The download attribute is working fine by downloading the file, but it is not getting the right file to download, so it ends up downloading the html of the page.
I think I have an issue with the server connect route not passing in correctly the id parameter.
This is my sc route: /api/IntakeForm/downloadForm/:id
and this is the anchor button:
Were you able to solve the problem? I can’t download the file via the API either. I get a CSV file in response, but instead of downloading it, Wappler converts it to JSON.
With API do you mean the server action or the API component? The API component cannot download files and with a server action you need to have a download action step inside it and then use a link tag for the download.
@patrick, I mean the server action. I make a GET request to the data provider and get a file in response.
I tried adding the “Download file” and “Export CSV” components after the “API connection”, but nothing worked out for me. If JSON comes in response, then it can be saved to a file using the “Export CSV” component, and if CSV comes in response, then this component no longer works.
So you are actually using the API Action component to connect to an external API - is that correct?
What is the response from this external API exactly?