Question

I want provide a rest service api by restify ( or express )

  • the duty of service is let client who could put audio/mpeg or other
    binary file to our server, and then verify the authentication, if
    pass, put the file to amazon s3, and then check the s3 client
    response statusCode, if s3 client reponse statusCode == 200 , do
    somethings

solution1: using request stream pipe to put files to amazon by knox

var stream = s3.put(filepath, {options});
serverReq.pipe(stream);
stream.on('response', function(err, s3Res) {
    if (err) { console.log(err); }
    if (s3Res.statusCode == 200) { store file infos on DB}
}

solution2: using formdiable and fs to pre store file on server local temp folder and then put files to amazon by knox

(after pre store file on server local temp folder)
s3.putFile(sourcePath, destPath, {options}, function(err, _res) {
    (clear local files from local temp folder)

    if (err) { return next(err); }
    if (_res.statusCode == 200) {console.log('save on %s', s3.url(dest))}
    res.send(_res.statusCode);
    return next();
});

which way is better between solution 1 and solution 2 or other better way ?? and does here has any performance issues need to know?

Was it helpful?

Solution

Depending on the server load and your available bandwidth, your diskio is your biggest potential bottleneck. I would say go with solution 1 that streams the file directly and doesn't store it to physical media. Make sure you don't attempt to store the entire object to memory either or you could run into a system resources problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top