Automattic / knox

S3 Lib
MIT License
1.74k stars 285 forks source link

putFile is not wornking since yesterday #243

Open burakkilic opened 10 years ago

burakkilic commented 10 years ago

Hi;

My upload to S3 code was working yesterday but now I am getting

Error: Request aborted
at IncomingMessage.onReqAborted (/node_modules/express/node_modules/connect/node_modules/multiparty/index.js:182:17)
at IncomingMessage.emit (events.js:92:17)
at abortIncoming (http.js:1911:11)
at Socket.serverSocketCloseListener (http.js:1923:5)
at Socket.emit (events.js:117:20)
at TCP.close (net.js:465:12)

What can be the problem?

domenic commented 10 years ago

I can't imagine how you expect us to be able to help you without posting some sample code.

burakkilic commented 10 years ago

Sorry about that:

var s3Client = knox.createClient({
    key: '****',
    secret: '********',
    bucket: 'myBucket'
});

And my uploader function:

exports.upload = function(req, res) {

var form = new multiparty.Form();
var batch = new Batch();
batch.push(function(cb) {
    form.on('field', function(name, value) {
        if (name === 'path') {
            var destPath = value;
            if (destPath[0] !== '/') destPath = '/' + destPath;
            cb(null, destPath);
        }
    });
});
batch.push(function(cb) {
    form.on('part', function(part) {
        if (!part.filename) return;
        cb(null, part);
    });
});
batch.end(function(err, results) {
    if (err) throw err;
    form.removeListener('close', onEnd);
    var destPath = results[0],
        part = results[1];

    headers['Content-Length'] = part.byteCount;
    s3Client.putStream(part, destPath, headers, function(err, s3Response) {
        if (err) throw err;
        res.statusCode = s3Response.statusCode;
        s3Response.pipe(res);
        console.log("https://s3.amazonaws.com/" + process.env.S3_BUCKET + destPath);
    });
});
form.on('close', onEnd);
form.parse(req);

function onEnd() {
    throw new Error("no uploaded file");
}
}

Nothing returns.