-
-
Save radiumrasheed/de5d41ea2ffbc57d6f80866c349d6774 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 hidden or 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