Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript S3节点模块,尝试上载文件时出错_Javascript_Node.js_Amazon Web Services_Amazon S3 - Fatal编程技术网

Javascript S3节点模块,尝试上载文件时出错

Javascript S3节点模块,尝试上载文件时出错,javascript,node.js,amazon-web-services,amazon-s3,Javascript,Node.js,Amazon Web Services,Amazon S3,我试图上传一个文件到我的AmazonS3存储桶,但我得到了一个ENETUNREACH错误。我确实有权上载/删除我的存储桶的文件,并且还编辑了CORS配置以允许所有来源的POST/GET请求。我想这可能是我从某人那里收到的有问题的钥匙。如果恰好是问题所在,那么什么是测试我拥有的密钥是否有效的好方法 代码如下: var s3 = require('s3'); /* Create a client for uploading or deleting files */ var client = s3.

我试图上传一个文件到我的AmazonS3存储桶,但我得到了一个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小文件时的控制台日志:


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

执行
控制台.log(客户端)
并发布输出。
ENETUNREACH
表示无法从该系统访问您尝试连接的地址的网络。169.x.x.x不是有效的可路由地址。您能从命令提示符成功ping您的s3主机名/地址吗?@peteb ping
https://s3-us-west-2.amazonaws.com
like@mscdex建议