简体   繁体   中英

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.

Here you can find my code to upload a file in a bucket recently (or not) created : 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 . If there is no error I display the response data time - debug : DATA . But nothing appears after 10 minutes. I'm using v1.3.2 of the library (the lastest stable version).

I try also to change the sendFile function like this (using the response for that question ) :

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+.

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 ..

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);
        }
    );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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