Created
July 23, 2014 09:36
-
-
Save roparz/e9dedb2b8d421d75b989 to your computer and use it in GitHub Desktop.
Rename object with Node.js AWS S3 (copy object then delete object) with promises
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
config = require 'config' | |
s3 = require 's3' | |
q = require 'q' | |
module.export = (oldKey, newKey) -> | |
defer = q.defer() | |
params = | |
# you need to set the s3 bucket in the CopySource key | |
CopySource: "#{ config.s3.bucket }/#{ oldKey }" | |
Key: newKey | |
s3.copyObject params, (err) -> | |
if err then defer.reject(err) | |
else s3.deleteObject Key: oldKey, (err) -> | |
if err then defer.reject(err) | |
else defer.resolve() | |
return defer.promise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one!