1

I just made an upload file to AWS S3 with sails and skipper-3 and it work well. Now, how can I delete a file in AWS S3 with Sails?

When I upload the file I store in the Database the URL to AWS S3.

JrBenito
  • 973
  • 8
  • 30

3 Answers3

5

skipper-s3 already contains functions to read,list or remove files. I am using below code to remove some file from the AWS S3. You can use it like this:

var skipper = require('skipper-s3')({key: KEY,secret: SECRET,bucket: BUCKET}); skipper.rm(imageName,function(){});

Check the module functions on source code

Ammy T
  • 551
  • 4
  • 4
2

You can use AWS-SDK directly or one of the many wrappers to it available at npm.

Based on Amazon documentation you will have something like:

s3.deleteObject(params, function(err, data) {
    if (err) console.log(err, err.stack);  // error
    else     console.log();                 // deleted
});

paramsshall hold parameters as bucket, credentials, region, path. See the example at Amazon nodejs examples.

And, for sure you can use the AWS SDK for upload files and use other AWS services inside sails too.

Your question is answered here too.

Community
  • 1
  • 1
JrBenito
  • 973
  • 8
  • 30
0

For single image delete at a time First, install:

npm install --save aws-sdk

Now write the below code:

var AWS = require("aws-sdk");

var s3 = new AWS.S3();

s3.config.update({
  accessKeyId: "your aws key",
  secretAccessKey: "your aws secret key"
});

s3.config.region = "your aws bucket region";


var params = {
  Bucket: "Bucket name",
  Key: "image name"
};

s3.deleteObject(params, function(err, data) {
  if (err) console.log(err, err.stack);
  // an error occurred
  console.log(data, "tttttttttttt"); // successful response
});
plabon
  • 31
  • 3