相关疑难解决方法(0)

axios从URL获取文件并上传到s3

我正在尝试使用 axios.get 从网站获取文件,然后将其直接上传到 S3。但是,文件已损坏或编码不正确,上传后无法打开。文件类型范围从 .jpg、.png 到 .pdf。这是我的代码:

axios.get(URL, {
  responseEncoding: 'binary',
  responseType: 'document',
}).then((response) => {
  return new Promise((resolve, reject) => {
    const s3Bucket = nconf.get('AWS_S3_BUCKET');

    s3.upload({
      'ACL': 'public-read',
      'Body': response.data,
      'Bucket': s3Bucket,
      'Key': `static/${filePath}/${fileManaged.get('filename')}`,
    }, function(err) {
      if (err) {
        return reject(err);
      }
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

我尝试使用 修改responseTypearraybuffer创建缓冲区Buffer.from(response.data, 'binary').toString('base64'),但无济于事。我缺少什么?

amazon-s3 node.js axios

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

amazon-s3 ×1

axios ×1

node.js ×1