Skip to content

I cant use Content-MD5 Header on presigned URL for command with putObject #1392

@rgarcia-martin

Description

@rgarcia-martin

Im trying to use a presigned url with that code:

$cmd = $s3Client->getCommand("PutObject", array(
            "Bucket" => $bucket["bucket"],
            "Key" => "prueba",
        ));
$request = $s3Client->createPresignedRequest($cmd, "+10 minutes");
$presignedUrl = (string) $request->getUri();

The URL generated is send to a mobile app that will upload the file. I need the mobile app check that the file is correctly uploaded using the Content-MD5 Header.

All time im trying to use this header, amazon returns AccessDenied with that message:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>AccessDenied</Code>
    <Message>There were headers present in the request which were not signed</Message>
    <HeadersNotSigned>content-md5</HeadersNotSigned>
</Error>

=================

I tried the following methods to add the Header to the presign process without results:

  • Add "Content-MD5" to params for initializate de S3Client
  • Add "Content-MD5" to params for getCommand function: getCommand("PutObject", ["Bucket" => "asdfsd", "Key" => "asdfsdf", "Content-MD5" => "sadfasdf"]
  • Create an Middleware::mapRequest for add the Header in Builder step:
$middelware = Middleware::mapRequest(function(RequestInterface $request){
            var_dump("map-request");
            var_dump($request);

            $r2 = $request->withHeader("Content-MD5", "FB1E00AB39252B6C3EBBFC14C53C636D");

            var_dump($r2);
            var_dump("end map-request");

            return $r2;
        });

        $list = $cmd->getHandlerList();
        $list->appendBuild($middelware);
  • Create an Middleware::mapRequest for add the Content-MD5 in the query params:
$middelware = Middleware::mapRequest(function(RequestInterface $request){
            var_dump("map-request");
            var_dump($request);

            $query = $request->getUri()->getQuery();
            if(!empty($query)){
                $query .= "&";
            }

            $query .= "Content-MD5=FB1E00AB39252B6C3EBBFC14C53C636D";

            $uri2 = $request->getUri()->withQuery($query);
            $r2 = $request->withUri($uri2);

            var_dump($r2);
            var_dump("end map-request");

            return $r2;
        });

        $list = $cmd->getHandlerList();
        $list->appendBuild($middelware);

But ALL TIME the $s3Client->createPresignedRequest($cmd, "+10 minutes") returns an RequestInterface without Content-MD5 Header signed and amazon return Error...

Thanks You for Helping! :D

Metadata

Metadata

Assignees

No one assigned

    Labels

    guidanceQuestion that needs advice or information.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions