How to Use $.respond to Send a File Download to the User's Computer

This topic was automatically generated from Slack. You can find the original thread here.

Hi everyone - does anyone know how to use $.respond to send back a file that the user will download to their computer?

I have a pipedream scenario triggered by a GET request. This will be initiated by a user entering the URL into their browser and hitting enter (or any other http way of sending a GET request).

The workflow does a bunch of stuff resulting in a file being created and saved to the /tmp directory of the workflow (a 10mb .json file “results.json”).

I need to finish the workflow by responding to the get request with the .json file, so the file is automatically downlodaed to the users computer. I ideally DON’T want to just show the JSON contents on-screen - it should be a file download.

Any help would be appreciated.

Thanks

So generally, you just need to respond with a Content-Type HTTP header to indicate to the browser / HTTP client calling the Pipedream endpoint what kind of data you’re sending back in the response, as well as the Content-Disposition header to indicate that you want the client to handle the data as an attachment (i.e. download it): Content-Disposition - HTTP | MDN

Thanks, that did the trick!