Posts

Showing posts with the label stream

How to stream object from AWS S3 to browser using node and angular

Image
1. Create an api get request to node application.   eg:    Get '/api/get-file/:id' 2. Install packages aws-sdk , or express npm i express aws-sdk , leave it if pre- installed. 3. Follow the below code snippet  Aws S3 service provide getObject and createReadStream method. Pass the Params to s3.getObject then use createReadStream. use pipe method in createReadStream and pass the response (res) object to pipe method so it will pipe your stream to response. You can also use file write Stream location to save Stream in file.   var   app  =  require ( 'express' )();   var   aws   =  require ( 'aws-sdk' );   aws . config . update ({  region :   'us-east-1'  });   var   s3  =  new   aws . S3 ({ apiVersion :   '2006-03-01' });   const   BUCKET  =  '<your bucket name>' ;       app . get ( '/api/ge...