aws-sdk s3上传无法使用mocha测试

时间:2016-05-20 03:47:26

标签: javascript node.js mocha aws-sdk

尝试从mocha测试中运行s3上传:

'use strict';

describe('S3 test', function() {
    it.only('S3 test 1', function*() {
        var AWS = require('aws-sdk');
        //AWS.config.region = 'us-west-2';
        var s3 = new AWS.S3({
            params: { Bucket: 'test-1-myBucket', Key: 'myKey' }
        });
        s3.createBucket(function(err) {
            if (err) {
                console.log("Error:", err);
            } else {
                s3.upload({
                    Body: 'Hello!'
                }, function() {
                    console.log("Successfully uploaded data to myBucket/myKey");
                });
            }
        });
    });
});

但没有任何反应,它根本没有发送http请求。那是为什么?

2 个答案:

答案 0 :(得分:2)

卫生署。它是异步的所以我需要使用完成回调:

&&

答案 1 :(得分:1)

可能缺少accessKeyId和secretAccessKey

var s3 = new AWS.S3({
    accessKeyId: "",
    secretAccessKey: ""
});

然后

s3.upload({
    Bucket: 'test-1-myBucket', 
    Key: 'myKey'
    Body: 'Hello!',    
}