S3节点模块,尝试上传文件会产生ENETUNREACH错误

时间:2016-03-10 16:39:37

标签: javascript node.js amazon-web-services amazon-s3

我尝试将文件上传到我的Amazon S3存储桶,但是我收到了ENETUNREACH错误。我有权上传/删除我的存储桶的文件,还编辑了CORS配置以允许来自所有来源的POST / GET请求。我认为这可能是我从某人那里得到的错误钥匙。如果碰巧是问题,测试我所拥有的密钥是否有效的好方法是什么?

以下代码:

var s3 = require('s3');

/* Create a client for uploading or deleting files */
var client = 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: 'xxxxxxxx',
        secretAccesskey: 'xxxxxxxx',
        region: 'xxxxxxxx'
    },
});

exports.uploadFile = function(fileName, bucket){
    console.log('Uploading File: ' +fileName+'\nBucket: ' +bucket);

    var params = {
        localFile: fileName, 

        s3Params: {
          Bucket: bucket,
          Key: 'testfile',
        },
    };

    var uploader = client.uploadFile(params);
    uploader.on('error', function(err) {
        console.error("unable to upload:", err.stack);

    });

    uploader.on('progress', function() {
        console.log("progress", uploader.progressMd5Amount, uploader.progressAmount, uploader.progressTotal);
    });

    uploader.on('end', function() {
        console.log("done uploading");
    });
};

尝试上传txt小文件时的控制台日志:

Console Log

1 个答案:

答案 0 :(得分:0)

禁用IIS服务以修复我的错误。