Last active
August 29, 2015 14:01
-
-
Save Meekohi/088886081deb828f4b4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This example throws this (uncatchable) exception: | |
/node_modules/aws-sdk/lib/request.js:34 | |
throw e; | |
^ | |
NoSuchKey: The specified key does not exist. | |
*/ | |
var secrets = require('./secrets').development; | |
// AWS | |
var AWS = require('aws-sdk'); | |
AWS.config.update(secrets.aws); | |
var s3 = new AWS.S3(); | |
var s3bucket = secrets.s3bucket; | |
function copyFile(cpObj, callback) | |
{ | |
s3.copyObject({Bucket: s3bucket, Key: cpObj.newKey, CopySource: s3bucket+"/"+cpObj.copySource, ACL: "public-read"}, function(err, data){ | |
if(err) { | |
console.dir(cpObj); | |
throw(err); | |
} | |
callback(null); | |
}); | |
} | |
var new_id = "f0g5i3u3uhv6"; | |
var old_id = "2ith82kkw2zu9"; | |
var oldKey = "2ith82kkw2zu9/orig/010.jpg"; | |
var newKey = oldKey.replace(old_id,new_id); | |
var opts = { | |
CopySource: s3bucket+"/"+oldKey, | |
Bucket: s3bucket, | |
Key: newKey, | |
ACL: "public-read" | |
}; | |
s3.copyObject(opts, function(err, data){ | |
if(err) { | |
console.error(opts); | |
throw(err); | |
} | |
return; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment