├── .gitignore ├── ajax-loader.gif ├── config.js ├── index.html ├── package.json └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | -------------------------------------------------------------------------------- /ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexzywiak/s3StreamExample/e9c30894b4abc3e478ef3c271bc6567f55ce4758/ajax-loader.gif -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | key : 'AKIAIYUNK7RG2IKRYJQA', 3 | secret: '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', 4 | bucket: 'New-Bucket-1020' 5 | }; -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | S3 Audio 5 | 6 | 7 | 8 | 9 |
10 | 11 |
12 | 13 | // 59 | 60 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "s3Stream", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node server.js" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "express": "^4.13.3", 14 | "s3": "^4.4.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var s3 = require('s3'); 3 | var config = require('./config'); 4 | var app = express(); 5 | 6 | // Set up s3 credentials 7 | var client = s3.createClient({ 8 | s3Options: { 9 | accessKeyId: config.key, 10 | secretAccessKey: config.secret 11 | } 12 | }); 13 | 14 | app.use('/', express.static(__dirname)); 15 | 16 | app.get('/audio', function(req, res) { 17 | 18 | var params = { 19 | Bucket: config.bucket, 20 | Key: 'test.mp3' 21 | }; 22 | 23 | var downloadStream = client.downloadStream(params); 24 | 25 | downloadStream.on('error', function() { 26 | res.status(404).send('Not Found'); 27 | }); 28 | downloadStream.on('httpHeaders', function(statusCode, headers, resp) { 29 | // Set Headers 30 | res.set({ 31 | 'Content-Type': headers['content-type'] 32 | }); 33 | }); 34 | 35 | // Pipe download stream to response 36 | downloadStream.pipe(res); 37 | }); 38 | 39 | app.listen(3000, function() { 40 | console.log('makin music on 3000'); 41 | }); 42 | --------------------------------------------------------------------------------