Stackoverflow has a few questions about this, but I cannot find the answer to your question. The solution below should work, however, I am having problems working with knox on my machine right now. Hope you are more lucky!
UPDATE: I seem to have had problems with s3 here, the code below - I really changed one, you need to specify encoding as null for the request, so you get the Buffer back. Otherwise, binary data will not work so well.
request(item.productImage, {encoding: null}, function(err, res, body) { if(!err && res.statusCode == 200) { var req = client.put('/item/' + item._id + '/' + filename, { 'Content-Type': res.headers['content-type'], 'Content-Length': res.headers['content-length'] }); req.on('response', function(res) { console.log('response from s3, status:', res.statusCode, 'url:', req.url); }); req.on('error', function(err) { console.error('Error uploading to s3:', err); }); req.end(body); } });
Note. With this solution, you avoid buffering files to disk - so I decided to use the put method of the lower level client knox.
source share