亚马逊s3 | MalformedXML状态代码:400

时间:2015-05-24 18:04:21

标签: php amazon-web-services amazon-s3

我在使用aws -sdk for php的putObject()函数时收到以下错误:

PHP Fatal error:  Uncaught Aws\S3\Exception\MalformedXMLException: AWS Error Code: MalformedXML, 
Status Code: 400, AWS Request ID: 7E36EB414B2A9436, AWS Error Type: client, 
AWS Error Message: The XML you provided was not well-formed or did not validate against our published schema, 
User-Agent: aws-sdk-php2/2.5.4 Guzzle/3.8.1 curl/7.26.0 PHP/5.5.19-1~dotdeb.1
  thrown in /sites/sitename/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91

即使我收到错误,该过程仍继续成功运行,文件将移至s3。我知道这很可能与我在函数中包含的参数有关,但我不确定还需要什么,因为aws api for php只显示'桶&# 39;和'关键'参数是必需的。我的配置如下:

$config = array();
$config['Bucket'] = IMAGE_BUCKET;
$config['Key'] = $imageName;
$config['SourceFile'] = $sourceImageDir;
$config['ACL'] = 'public-read';
$config['ContentLength'] = filesize($sourceImageDir);

$response = $s3->putObject($config);

如果我知道该服务需要什么格式,我确定我可以抓住我在发送到xml字符串后发送的请求并将其与之比较,但我可以&似乎找不到它。如果它存在。我会假设有这样的事情吗?

1 个答案:

答案 0 :(得分:0)

感谢迈克尔的评论,我能够进一步追踪这个问题。事实证明,问题实际上来自对deleteObjects()的调用。这些命令正在cli上的shell脚本中执行,结果是在最后一次调用putObject()之前还有另一个调用。它试图将空数组发送到s3服务......这显然会返回给定的MalformedXML状态代码。