admin管理员组文章数量:1391929
I would like to be able to POST to my express app with a file URL and download that file to my own server.
For example, I display a list of images that are taken from a third-party and when the user clicks download, it will send a post request to this node app with the file URL (.jpg) and download it to my server.
How would I do this? I apologize as I'm very new to node.
I would like to be able to POST to my express app with a file URL and download that file to my own server.
For example, I display a list of images that are taken from a third-party and when the user clicks download, it will send a post request to this node app with the file URL (http://example./image.jpg) and download it to my server.
How would I do this? I apologize as I'm very new to node.
Share Improve this question asked Jul 2, 2014 at 15:21 EverestEverest 6076 silver badges13 bronze badges2 Answers
Reset to default 3To download a remote file from node you could save what you would get from a http GET request to that file:
var http = require('http');
var fs = require('fs');//Handle files
var fileToDownload=req.body.fileToDownload;
var file = fs.createWriteStream("externalImage.jpg");
var request = http.get(fileToDownload, function(response) {
response.pipe(file);
});
Use the Formidable module to handle file uploads. It handles many tasks and features related to file upload.
npm install formidable@latest
本文标签: javascriptUpload a file to server via URL using nodejs and expressjsStack Overflow
版权声明:本文标题:javascript - Upload a file to server via URL using nodejs and expressjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744734106a2622220.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论