简体   繁体   English

无法在Amazon S3上上传文件

[英]Can't upload file on Amazon S3

All works fine for me with the AWS-SDK for JavaScript but I think there is something weird that prevents me upload a file in a bucket that I just created. 所有适用于JavaScript的AWS-SDK都对我来说很好用,但我认为有些奇怪的事情使我无法将文件上传到刚创建的存储桶中。

Here you can find my code to upload a file in a bucket recently (or not) created : http://pastebin.com/X2x2TYzQ 在这里,您可以找到我的代码以上传(或未创建)最近创建的存储桶中的文件: http : //pastebin.com/X2x2TYzQ

Console output : 控制台输出:

2013-07-09T11:28:16.428Z - trace: UPLOAD : UPLOAD_FILES
2013-07-09T11:28:16.430Z - data: @FILES : [object Object]
2013-07-09T11:28:16.430Z - data: @BUCKET_NAME : mllXkdjSi8736gdjUUEyhhsbkfliofuzbb00D9f
2013-07-09T11:28:16.431Z - data: @RESPONSE_FORMAT : json
2013-07-09T11:28:16.432Z - trace: UPLOADER : SEND_FILES_TO_AMAZON_S3
2013-07-09T11:28:16.432Z - trace: UPLOADER : IS_BUCKET_CREATED
2013-07-09T11:28:16.855Z - debug:  Buckets=[Name=mllxkdjsi8736gdjuueyhhsbkfliofuzbb00d9f, CreationDate=Tue Jul 09 2013 11:16:01 GMT+0000 (UTC)], ID=08585ce13e82846e44f03248bc73f2bc80e847ed3a529f3d53d3723228ba6fd8, DisplayName=amazon, RequestId=61C098432063348A
2013-07-09T11:28:16.857Z - info: bucket found
2013-07-09T11:28:16.858Z - trace: UPLOADER : SEND_FILES
2013-07-09T11:28:16.858Z - debug:  size=4746, path=/tmp/db16391116623ebebc829db08ff8422e, name=Icon@2x.jpg, type=image/jpeg
2013-07-09T11:28:16.859Z - trace: UPLOADER : SEND_FILE

If the callback send me an error I display an error message like time - error : MESSAGE_ERROR . 如果回调向我发送错误,则显示错误消息,例如time - error : MESSAGE_ERROR If there is no error I display the response data time - debug : DATA . 如果没有错误,我将显示响应数据time - debug : DATA But nothing appears after 10 minutes. 但是10分钟后什么也没出现。 I'm using v1.3.2 of the library (the lastest stable version). 我正在使用该库的v1.3.2 (最新的稳定版本)。

I try also to change the sendFile function like this (using the response for that question ) : 我也尝试像这样更改sendFile函数(使用该问题的响应):

function sendFile(options, done) {
    logger.trace('UPLOADER : SEND_FILE');

    s3.putObject(options)
        .done(function (data) {
            logger.debug(data);

            done();
        })
        .fail(function (err) {
            done(err);
        })
        .send();
}

But same thing no message displayed. 但同样的事情,没有消息显示。

Any idea ? 任何想法 ?

Thank you. 谢谢。

Problem solved with the help of someone on Google+. 在Google+上某人的帮助下解决了问题。

On line 101 to 104 I'm using a callback function named callback but I have not define this function but rather a function named done .. 在101到104行上,我使用的是名为callback的回调函数,但我尚未定义此函数,而是定义了done函数。

function sendFiles(object, done) {
    logger.trace('UPLOADER : SEND_FILES');

    var urls = [];

    async.eachSeries(
        object.data,
        function (file, cb) {
            logger.debug(file);

            var file_name = random({length: 30}).toLowerCase();

            switch (file.type) {
                case 'image/jpeg':
                    file_name += '.jpg';
                    break;
                default:
                    cb(new Error('Unknown image file type'));
            }

            var options = {
                Bucket: object.bucket_name,
                ACL: 'public-read',
                Key: file_name,
                ContentLength: file.size,
                ContentType: file.type,
                Body: fs.readFileSync(file.path)
            };

            sendFile(
                options,
                function (err) {
                    if (err) {
                        return cb(err);
                    }

                    urls.push(object.location + file_name);

                    cb();
                }
            );
        },
        function (err) {
            if (err) {
                return callback(err);
            }

            callback(null, urls);
        }
    );
}

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

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