whitwhoa
whitwhoa

Reputation: 2489

Amazon s3 | MalformedXML Status Code: 400

I am receiving the following error when using the putObject() function of the aws-sdk for php:

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

Even though I am receiving the error, the process continues to run successfully and the files are moved to s3. I know this more than likely has something to do with the parameters that I am including in the function but I'm not sure what else needs to be there as the aws api for php only shows the 'bucket' and 'key' parameters as being required. My configuration is as follows:

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

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

If I knew what format the service was requiring I'm sure I could grab the request that I'm sending after it's turned into an xml string and compare it with that, but I can't seem to find it. If it exists. I would assume there is such a thing?

Upvotes: 0

Views: 2803

Answers (1)

whitwhoa
whitwhoa

Reputation: 2489

Thanks to the comment from Michael I was able to track the issue down further. It turns out that the issue was actually coming from a call to deleteObjects(). These commands are being executed within a shell script on the cli and it turns out there was another call preceeding the last call to putObject(). It was trying to send empty arrays to the s3 service...which would obviously return the given MalformedXML Status code.

Upvotes: 0

Related Questions