我尝试使用node js创建一个下载功能并重新进行验证,但是它只返回文件名而不下载,有人可以指出吗?
const wrapper = require('../../../../helpers/utils/wrapper');
const Restify = require('restify');
const Fs = require('fs');
const Path = require('path');
class Download {
async getDownload(payload) {
var url = payload.url;
const extension = url[url.length - 1];
const nameImage = `Photo${Math.random(100)}.${extension}`;
const path = Path.resolve(__dirname, 'C:\\Users\\User\\Downloads',
nameImage);
Fs.createWriteStream(path);
const data = {
'From URL': url,
'Download Succesfull at Location': path
};
return wrapper.data(data, '', 200);
}
}
module.exports = Download;