Skip to content

Instantly share code, notes, and snippets.

@nicooprat
Created June 23, 2016 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicooprat/5ee6a22212faf049140ebf5a4df89380 to your computer and use it in GitHub Desktop.
Save nicooprat/5ee6a22212faf049140ebf5a4df89380 to your computer and use it in GitHub Desktop.
S3 Delete File Lepozepo/S3#114
Future = Npm.require 'fibers/future'
Meteor.methods
_s3_delete: (path) ->
@unblock()
check path,String
future = new Future()
if S3.rules?.delete
delete_context = _.extend this,
s3_delete_path:path
auth_function = _.bind S3.rules.delete,delete_context
if not auth_function()
throw new Meteor.Error "Unauthorized", "Delete not allowed"
params =
Bucket: path.split('/')[1]
Key: path.split('/')[2]
S3.aws.deleteObject params, (e,r) ->
if e
future.return e
else
future.return true
future.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment