Skip to content

Instantly share code, notes, and snippets.

@mikermcneil
Created March 12, 2013 06:33
Show Gist options
  • Save mikermcneil/5140782 to your computer and use it in GitHub Desktop.
Save mikermcneil/5140782 to your computer and use it in GitHub Desktop.
multi-part s3 streaming upload from another url
var fs = require('fs');
var knox = require('knox');
var mpu = require('knox-mpu');
var request = require('request');
var uri = "https://lh4.ggpht.com/N5f6FA5zPjrTH-UggaFLstYSO1za-01CbsO17ZwkghtF0k9TSzWcnCn4bybCDeIOP4cu=w124";
// Open download stream from google
var downStream = request(uri);
// Open temp file ("upload" stream)
// var tempFile = fs.createWriteStream('stupidTempFile.png');
// Create a Knox client first
var knoxClient = knox.createClient({
key: 'AKIAILI5SA5VKWYWVENQ',
secret: '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',
bucket: 'game-icons'
});
// Use crazy knox-mpu syntax to pipe downstream to upstream
var upload = null;
upload = new mpu({
client: knoxClient,
objectName: 'omgFinally.png', // Amazon S3 object name
stream: downStream
},
// Callback handler
function(err, res) {
// If successful, will return a JSON object containing Location, Bucket, Key and ETag of the object
if (err) console.error(err);
console.log('Success');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment