如何使用Restify下载数据?

时间:2019-05-23 03:42:20

标签: node.js restify

我尝试使用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;

0 个答案:

没有答案