akn*_*ds1 15 javascript rest node.js aws-sdk
使用AWS SDK for Node,为什么在尝试删除不存在的对象时(即S3键错误),我不会收到错误?
另一方面,如果我指定不存在的存储桶,则会产生错误.
如果考虑以下Node程序,该Key
参数会列出存储桶中不存在的密钥,但error
回调的参数为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)
})
Run Code Online (Sandbox Code Playgroud)