Sunday, 15 August 2010

node.js - What "streams and pipe-capable" means in pkgcloud in NodeJS -



node.js - What "streams and pipe-capable" means in pkgcloud in NodeJS -

my issue image uploading amazon working. looking solution doesnt save file on server , then upload amazon.

googling found pkgcloud , on readme.md says:

special attending has been paid methods streams , pipe-capable.

can explain means , if looking for?

yupp, means you've found right kind of s3 library.

what means library exposes "streams". here api defines stream: http://nodejs.org/api/stream.html

using node's stream interface, can pipe readable stream (in case post's body) writable stream (in case s3 upload).

here illustration of how pipe file upload straight kind of library supports streams: how handle posted files in express.js without doing disk write

edit: here example

var pkgcloud = require('pkgcloud'), fs = require('fs'); var s3client = pkgcloud.storage.createclient({ /* ... */ }); app.post('/upload', function(req, res) { var s3upload = s3client.upload({ container: 'a-container', remote: 'remote-file-name.txt' }) // pipe image info straight s3 req.pipe(s3upload); });

edit: finish answering questions came in chat:

req.end() automatically phone call s3upload.end() stream magic. if op wants else on req's end, can easily: req.on('end', res.send("done!"))

node.js amazon-s3 pkgcloud

No comments:

Post a Comment