为什么S3.deleteObject在指定的键不存在时不会失败? [英] Why does S3.deleteObject not fail when the specified key doesn't exist?

查看:629
本文介绍了为什么S3.deleteObject在指定的键不存在时不会失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 AWS SDK for Node ,为什么我没有获得尝试删除不存在的对象时出错(即S3键错误)?

Using the AWS SDK for Node, why do I not get an error when trying to delete an object that doesn't exist (i.e. the S3 key is wrong)?

如果我另外指定一个不存在的存储桶,产生错误。

If I specify a non-existent bucket on the other hand, an error is produced.

如果您考虑以下Node程序, Key 参数列出了一个没有的密钥存在于桶中,但回调的错误参数是 null

If you consider the following Node program, the Key parameter lists a key which doesn't exist in the bucket, yet the error argument to the callback is null:

var aws = require('aws-sdk')

function getSetting(name) {
  var value = process.env[name]
  if (value == null) {
    throw new Error('You must set the environment variable ' + name)
  }
  return value
}

var s3Client = new aws.S3({
  accessKeyId: getSetting('AWSACCESSKEYID'),
  secretAccessKey: getSetting('AWSSECRETACCESSKEY'),
  region: getSetting('AWSREGION'),
  params: {
    Bucket: getSetting('S3BUCKET'),
  },
})
picturePath = 'nothing/here'
s3Client.deleteObject({
  Key: picturePath,
}, function (err, data) {
  console.log('Delete object callback:', err)
})


推荐答案

因为那是 specs 表示应该这样做。

Because that's what the specs say it should do.


deleteObject(params = {},callback)⇒AWS.Request

删除对象的null版本(如果有的话)并插入
删除标记,该标记将成为对象的最新版本。如果
没有空版本,则Amazon S3不会删除任何对象。

Removes the null version (if there is one) of an object and inserts a delete marker, which becomes the latest version of the object. If there isn't a null version, Amazon S3 does not remove any objects.

因此,如果对象没有如果存在,调用 deleteObject 时仍然不是错误,它仍会添加删除标记。

So if the object doesn't exist, it's still not an error when calling deleteObject, it still adds the delete marker.

这篇关于为什么S3.deleteObject在指定的键不存在时不会失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆