Node download file






















Now you need to create a new writable stream using fs. The fs module will create the writable stream on the current folder by default:. Finally, send the GET response data stream to the writeStream object using the pipe method. When the writeStream sends the finish signal, close the writeStream object:. You can get the command-line arguments from the process. Get the SourceForge newsletter. JavaScript is required for this form.

No, thanks. Mit einem Experten sprechen. Thanks for helping keep SourceForge clean. X You seem to have CSS turned off. Leave a Reply Cancel reply Your email address will not be published. Save my name, email, and website in this browser for the next time I comment. Necessary cookies are absolutely essential for the website to function properly.

This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information. Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. You can set the header value to whatever you like. In this case, I am using a mime-type library - node-mime , to check what the mime-type of the file is.

Another important thing to note here is that I have changed your code to use a readStream. This is a much better way to do things because using any method with 'Sync' in the name is frowned upon because node is meant to be asynchronous. How are we doing? Please help us improve Stack Overflow. Take our short survey. 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. Asked 10 years, 2 months ago. Active 2 months ago. Viewed k times. We can also specify the file name in this header. Another header is Content-Type , this contains the type of content or file type.

Now run server. Your file will be download. In Express. Here [] indicates the optional parameter. First parameter is. We can use both relative as well as absolute path. Another parameter is filename and the last parameter is function we will use to handle errors.



0コメント

  • 1000 / 1000