繁体   English   中英

亚马逊s3文件下载返回404

[英]amazon s3 file download returns 404

我正在尝试在s3中下载文件。 我遵循了https://www.npmjs.com/package/s3上的s3库,但无法下载文件。 并且错误消息不清楚。 它显示“错误:http状态代码404”。 我想念什么?

var fs = require('fs');
var s3 = require('s3');
var stdio = require('stdio');

var client = s3.createClient({
  s3Options: {
    accessKeyId: "access key id",
    secretAccessKey: "secret access key",
  },
});



var params = {
    localFile: "home/download",

    s3Params: {
      Bucket:  "bucketname",
      Key: "/folder1/folder2/folder3/fileName",
    },
};

var downloader = client.downloadFile(params);
downloader.on('error', function(err) {
  console.error("unable to download:", err.stack);
  //err.stack returns as "Error: http status code 404"
});
downloader.on('progress', function() {
  console.log("progress", downloader.progressAmount, downloader.progressTotal);
});
downloader.on('end', function() {
  console.log("done downloading");
});

我调试了您的代码,并在S3上放置了一个私人文件,并在使用您提到的上述代码时遇到了相同的错误。 s3客户端初始化的问题是我修复s3客户端的方法。

如果您阅读文档,他们会提到如何使用AWS-S3 https://www.npmjs.com/package/s3#create-a-client-from-existing-awss3-object进行配置

var fs = require('fs');
var s3 = require('s3');
var stdio = require('stdio');
var AWS =require('aws-sdk')

var client1 = s3.createClient({
  maxAsyncS3: 20,     // this is the default
  s3RetryCount: 3,    // this is the default
  s3RetryDelay: 1000, // this is the default
  multipartUploadThreshold: 20971520, // this is the default (20 MB)
  multipartUploadSize: 15728640, // this is the default (15 MB)
  s3Options: {
    accessKeyId: "***********",
    secretAccessKey: "********"
  },
});




// initilize wtih s3 client
var awsS3Client = new AWS.S3(client1);
var options = {
  s3Client: awsS3Client,
  // more options available. See API docs below.
};
var client = s3.createClient(options);

var params = {
  // local directory with file name
    localFile: "./test.jpg",

    s3Params: {
      // bucket name 
      Bucket:  "cf-logs.test.com",
      // folder and file name to download
      Key: "test/Horse Racing.jpg",
    },
};

var downloader = client.downloadFile(params);
downloader.on('error', function(err) {
  console.error("unable to download:", err.stack);
  //err.stack returns as "Error: http status code 404"
});
downloader.on('progress', function() {
  console.log("progress", downloader.progressAmount, downloader.progressTotal);
});
downloader.on('end', function() {
  console.log("done downloading");
});

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM