2

更新:在向该用户添加完全访问策略权限后,它可以从命令行工作。现在,当我使用 Node 执行此操作时,没有错误,但我在 s3 文件管理器中看不到文件。

使用 Amazon 的 S3 服务时,我不断收到 EPIPE 错误。

我有点卡住,不确定如何进行。

我将 Node.js 与Knox 模块一起使用。

这是我的代码:

var client = knox.createClient({
    key: amazonAccessKeyId,
    secret: amazonSecretAccessKey,
    bucket: amazonBucketName
});

function moveFiles() {
    moveUploadedFile(req.files['aps-file'].path,'/aps-products.csv', this.parallel());
    moveUploadedFile(req.files['perry-craft-roof-file'].path,'/perry-craft-roof-products.csv', this.parallel());
    res.end('successful!');
}

function moveUploadedFile(srcPath, dstPath, callback) {
    client.putFile(srcPath, dstPath, { 'x-amz-acl': 'public' }, function (err) {
        if (err) {
            callback(new Error("Error uploading file for " + dstPath + ": " + err.message), srcPath);
            console.log(err);
            return;
        }

        console.log('Finished writing file ' + dstPath + ' to Amazon S3 Cloud');
        callback(null, srcPath);
    });
}
4

1 回答 1

1

好的,这些是我为解决此问题而采取的步骤:

  1. 安装的 aws 命令行工具你可以在这里找到它:http: //www.timkay.com/aws/
  2. 为我创建的 s3 用户添加了完全访问(管理员访问)策略。
  3. 确保我可以使用以下命令写入该存储桶:aws put /file/to/put /new-file.
  4. {'x-amz-acl': 'public' }应该删除它,'public-read'否则它不会将文件添加到 s3(没有错误)。请注意,这{'x-amz-acl': 'private' }也有效。
于 2012-08-16T00:23:49.967 回答