如何从Angular端删除AWS S3存储桶的映像?

时间:2017-10-16 10:40:12

标签: angularjs

s3.getSignedUrl('putObject', param, function(err, url) {
    Console.log(url);
});

此方法用于添加图像。我应该用它来从Angular中删除图像吗?

1 个答案:

答案 0 :(得分:1)

var s3 = new AWS.S3({
        params: {
          Bucket: bucketName
        },
        accessKeyId: accessKeyId,
        secretAccessKey: secretAccessKey
      });

      var params = {
        Bucket: bucketName,
        Delimiter: '/',
        Prefix:  "/"
      }

      var ok = "";
      s3.listObjects(params, function (err, data) {
        if (err) throw err;
        for (var i = 0; i < data.Contents.length; i++) {
          if (data.Contents[i].Key.indexOf(remainingKey) > -1) {
            ok = data.Contents[i].Key;
            var params1 = {
              Bucket: bucketName,
              Key: ok
            };
            s3.deleteObject(params1, function (err, data) {

            });
          }
        }
      });

有关详细信息http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteBucket-property