I am using Node.js Request module to server file form remote server to user Browser .
Here is code i use :
expressjs_app.get("/file_url", function(req, res){
request.get('remote_file_url').pipe(res);
});
Everything works fine , I just want know it possible to change filename for user in Browser ?
Update
I sending remote file to user for download , i want when user want save file there is be different name other than orginal file name.
For example if remote file is: http:// domain.com/file1.zip
i want change filename to http:// mydomain.com/myfile.zip
The __filename represents the filename of the code being executed. This is the resolved absolute path of this code file. For a main program, this is not necessarily the same filename used in the command line. The value inside a module is the path to that module file.
The createWriteStream() method is an inbuilt application programming interface of fs module which allows to quickly make a writable stream for the purpose of writing data to a file. This method may be a smarter option compared to methods like fs. writeFile when it comes to very large amounts of data.
A readable stream is an abstraction for a source from which data can be consumed. An example of that is the fs. createReadStream method. A writable stream is an abstraction for a destination to which data can be written.
PassThrough. This Stream is a trivial implementation of a Transform stream that simply passes the input bytes across to the output.
You need to set a header in the response:
expressjs_app.get("/file_url", function(req, res){
res.header('Content-Disposition', 'attachment; filename="new file name.pdf"');
request.get('remote_file_url').pipe(res);
});
Easy enough. Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With