-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
guidanceQuestion that needs advice or information.Question that needs advice or information.
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
guidanceQuestion that needs advice or information.Question that needs advice or information.