How do I delete an object on AWS S3 using Javascript?

前端 未结 5 1267
予麋鹿
予麋鹿 2020-12-13 17:22

I want to delete a file from Amazon S3 using Javascript. I have already uploaded the file using Javascript. Any ideas?

5条回答
  •  既然无缘
    2020-12-13 18:19

    You can use construction like this:

    var params = {
      Bucket: 'yourBucketName',
      Key: 'fileName'
      /* 
         where value for 'Key' equals 'pathName1/pathName2/.../pathNameN/fileName.ext'
         - full path name to your file without '/' at the beginning
      */
    };
    
    s3.deleteObject(params, function(err, data) {
      if (err) console.log(err, err.stack); // an error occurred
      else     console.log(data);           // successful response
    });
    

    And don't forget to wrap it to the Promise.

提交回复
热议问题