Create download link with webhook response

At a certain point I need to pass a file through an api it does not receive a binary, only through a link like this http://nextcloud.ruansantana.com.br/s/CokbemJwMFnx65n/download/Nextcloud%20Manual.pdf I want to know if it is Is it possible to do something similar on the n8n? I created a flow where I accessed via webhooks and returned a binary but it didn’t work, does anyone have a solution for this?

Hey @Ruan17,

Just to check are you wanting to make a workflow that returns binary data? It looks like the Respond to Webhook node supports returning binary data so it would be possible but some thought would have to be put in to work out where the data is being saved and pulled from.

I can get the binary data, but it’s not what I want, I want to make a flow that when I access the webhook through the browser it already downloads the file, like this link I put up there

Hey @Ruan17,

Getting the binary data is just one part the important bit would be to use the Respond to Webhook node and tell it to respond with the binary data. The workflow below should do what you are after, I have used an HTTP Request node just to get a bit of binary data.

The URL to use would be something like https://n8n.yourdomain.tld/webhook-test/877b9ffd-9f97-446e-9319-3e0060655c70/download/5MB.zip and this will result in the browser downloading a zip file, This could be different depending on what the file is and if the browser knows how to open it like a pdf maybe.

I did it like this, but it opened the file in the browser, but I want it to download, is there any way?

Hey @Ruan17,

The problem is the browser knows what a PDF is and it is capable of reading it so to get around that you can use a Content-Disposition header and set the value to attachment this tells the browser to download the file instead.

You can read about this header option here: Content-Disposition - HTTP | MDN

To add it to your workflow in the Respond to Webhook Node add a response header and set the name to Content-Disposition and the value to attachment

2 Likes

I thought it would be something impossible to do. BUT WE DID IT! THANK YOU SO MUCH JON!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.