How to trigger file download from post request






















Writing code in comment? Please use ide. Load Comments. What's New. Most popular in JavaScript. JavaScript console. Most visited in Web Technologies.

Installation of Node. If you need your webapp to offer a file download for an asset created on the fly, like say a PDF generated from content entered by a user, how do you do that? This was a puzzle I encountered not too long ago on a personal proejct. I dug around and found a pretty solid solution, which I'll detail in this post. Photo by Mandi Cai. Module dependency for FileUpload: angular-file-download gulp install angular-file-download --save.

Registration looks like below. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. Ask Question. Asked 7 years, 4 months ago. Active 2 years, 5 months ago. Viewed k times. Additionally, the file being returned is a binary file, and AJAX is not intended for that. Improve this question. Community Bot 1 1 1 silver badge.

Why do you need a custom request header? You'll have to proxy this server-side. Why don't you just use the download attribute if you have a link to a file? Show 6 more comments. I have another line of code as shown blow, which will give users Save As option. Next we have render function to render the elements of React app. Elements are the building blocks of React apps.

As we said in Introduction section that we will give users two options for downloading file using link or using button. So in this render function we define our HTML elements with button and link to download file. Export the DownloadFile at the end of the DownloadFile class so that you can use this class in other modules, such as, I have used it later in below index.

Notice I had included download. This file is put under the src directory. The download. Update the index.



0コメント

  • 1000 / 1000