使用copy_object()时,AWS S3给出InvalidDigest[您指定的Content-MD5无效]错误


AWS S3 gives InvalidDigest [The Content-MD5 you specified was invalid] Error while copy_object() is used

我已经开始使用AWS S3服务,并成功地创建了存储桶以及将对象上传到任何存储桶中。但是当我试图将对象从一个桶复制到另一个桶时,我在响应中得到了这个异常。

我使用的是:http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html m = AmazonS3/copy_object

Exception I got is

[body] => CFSimpleXML Object
    (
        [Code] => InvalidDigest
        [Message] => The Content-MD5 you specified was invalid
    )
[status] => 400

示例我使用的代码是:

    $Connection = new AmazonS3(array(
    'key' => AWS_KEY,
    'secret' => AWS_SECRET_KEY
        ));
     $Connection->set_hostname($HOST);
     $Connection->allow_hostname_override(false);
     $Connection->enable_path_style();
     $res = $Connection->copy_object(
        array('bucket' => $bucket, 'filename' => ("boxdata/asset4053/images/yesteryear.png")), 
        array('bucket' => $bucket, 'filename' => 'test123.png'), 
        array('acl' => AmazonS3::ACL_PUBLIC,
            'storage' => AmazonS3::STORAGE_STANDARD,
            'metadataDirective' => 'COPY')
);

非常感谢!

这是一个老问题,但我遇到了同样的问题,并找到了解决方案。在发送给copy_object的选项列表中添加NoContentMD5 => true。

 $res = $Connection->copy_object(
    array('bucket' => $bucket, 'filename' => 'test123.png'), 
    array('bucket' => $bucket, 'filename' => 'test456.png'), 
    array('NoContentMD5' => true)
 );