Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

putFile is not wornking since yesterday #243

Open
burakkilic opened this issue Aug 15, 2014 · 2 comments
Open

putFile is not wornking since yesterday #243

burakkilic opened this issue Aug 15, 2014 · 2 comments

Comments

@burakkilic
Copy link

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
Copy link
Contributor

domenic commented Aug 25, 2014

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

@burakkilic
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants