Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete files off S3 #50

Closed
centinel3 opened this issue Jan 18, 2015 · 13 comments
Closed

Delete files off S3 #50

centinel3 opened this issue Jan 18, 2015 · 13 comments

Comments

@centinel3
Copy link

Feature request:

Are there any plans to allow the user to delete/remove files off amazon S3 storage?

Thanks and will talk with you soon. -Chris

@gsuess
Copy link
Contributor

gsuess commented Jan 18, 2015

Hey, this is currently not within the scope of the package. I would recommend using knox or similar to send delete request from the meteor server (not the client browser).

@centinel3
Copy link
Author

Ok. Thanks!

With this package do you have access to Knox server side?

@gsuess
Copy link
Contributor

gsuess commented Jan 18, 2015

No, but there are plenty of packages available for knox. It doens't have to be knox either there is also aws-sdk.

The reason Slingshot doesn't provide any of that, is because it is supposed to be lightweight.

Organizing and deleting files from the bucket is not something that should be handled by slingshot directives.

@centinel3
Copy link
Author

Thanks again. Love the package! Talk with you later. -Chris

@vertangelx
Copy link

I need this feature as well. Any recommendations for a Meteor package that is lightweight enough for use with the sole purpose of deleting files?

Maybe a delete-only version of slingshot?

@gsuess
Copy link
Contributor

gsuess commented Jan 20, 2015

You can try this:

Meteor.methods({
  deleteFile: function (key) {
    //TODO Check if authorization etc...

   HTTP.call("DELETE", Slingshot.S3Storage.bucketUrl("mybucket", region) + "/" + key, {
     headers: {
        authorization: Slingshot.S3Storage.signAwsV4(canonicalRequest, AWSSecretAccessKey, date, region, "s3")
     }
   });
  });
});

So you need region, canonincalRequest (see docs below), AWSSecretAccessKey and the date (yyyymmdd).

I believe future future versions of slingshot will have a canonicalRequest method that you can use as it will be needed for #5.

http:https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html

@gsuess gsuess closed this as completed Jan 21, 2015
@meteorjs3000
Copy link

@gsuess How do you get canonicalRequest and date? Do you store date in Mongodb when the file was initially uploaded to S3 so you can retrieve it now when deleting that file?

@centinel3
Copy link
Author

@gsuess
Thank you again for the nudge in the right direction. Much appreciated!

For anyone looking to delete off Amazon S3, see my code snippet below.
(be sure to download and install an Amazon SDK package from Meteor Atmosphere)

(On a server method):

AWS.config.update({
   accessKeyId: Meteor.settings.private.amazonS3.AWSAccessKeyId,
   secretAccessKey: Meteor.settings.private.amazonS3.AWSSecretAccessKey
});

var s3 = new AWS.S3();
   var params = {
   Bucket: Meteor.settings.private.amazonS3.bucket,
   Key: data.Key
};

var deleteObject = Meteor.wrapAsync(
   s3.deleteObject(params, function(error, data) {
      if(error) {
         console.log(error);
      } else {
         console.log(data);
      }
   })
);

Thanks again,
Chris Campbell
http:https://cleaved.com

@filipecoelho
Copy link

Hello @centinel3, what would be the data.Key?

@filipecoelho
Copy link

Hum, now I did!!
Is the name of the file or the real path key created at the time of storage. In my case it photos / 1342asf1sag3520_42tdgklaat02tmsga.png

@centinel3
Copy link
Author

Yes, the key is the path to the blob object. Glad you figured it out!

@markshust
Copy link

Has anyone done this with Google Cloud Storage?

@Roshdy
Copy link

Roshdy commented Aug 6, 2017

@centinel3 can you please post a sample call from client?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants