[英]AWS-SDK S3 deleteObjects Returning MalformedXML?
Using the aws-sdk (2.0.18) for node.js, i'm trying to delete multiple objects using the deleteObjects
method. 我将aws-sdk(2.0.18)用于node.js,我正在尝试使用
deleteObjects
方法删除多个对象。
delete: function (objects, callback) {
var s3delete = new AWS.S3();
var params = {
Bucket: config.s3.bucket,
Delete: {
Objects: objects
}
};
s3delete.deleteObjects(params, function (err, deleted) {
if (err) {
console.log(err, err.stack);
return callback(err);
}
return callback(null, deleted);
});
}
My params object looks like this: 我的params对象看起来像这样:
{ Bucket: 'bucketname',
Delete: {
Objects:[
{"Key":"folder/file.extension"},
{"Key":"folder/file.extension"},
{"Key":"folder/file.extension"},
{"Key":"folder/file.extension"},
{"Key":"folder/file.extension"},
{"Key":"folder/file.extension"},
{"Key":"folder/file.extension"}
]
}
}
This returns the following error: 这将返回以下错误:
{
message: "The XML you provided was not well-formed or did not validate against our published schema",
code: "MalformedXML",
time: "2014-10-11T10:35:52.525Z",
statusCode: 400,
retryable: false
}
According to the API spec , this should work. 根据API规范 ,这应该可行。 FYI: I'm passing in the
objects
argument from a Mongoose Model, it is stored as Mixed in Mongoose. 仅供参考:我从猫鼬模型传入了
objects
参数,它作为混合存储在Mongoose中。
This was caused by Mongoose returning malformed JSON objects in the original objects
array. 这是由猫鼬在原始
objects
数组中返回格式错误的JSON对象引起的。
In order to fix this specifically, I had to create a new Object and push them to a new array, in this specific case: 为了专门解决此问题,在这种特定情况下,我必须创建一个新的Object并将其推送到新的数组:
var s3Objects = [];
objects.forEach(function(ele, index, arr) {
console.log(index + ': ' + ele.Key);
var thisKey = {
Key: ele.Key
};
s3Objects.push(thisKey);
});
Then passed in s3Objects
to the params: 然后将
s3Objects
传递给参数:
var params = {
Bucket: config.s3.bucket,
Delete: {
Objects: properObjects
}
};
It now works. 现在可以使用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.