0

I successfully uploaded files in amazon s3 storage bucket with private mode.I need to access the file with in my default time. Am using luman laravel for my application

Here my code to get file:
$bucket="liv";
$resource="Arsenal-Wallpapers.jpeg"; 
$folde="testr";
$AWS_S3_KEY="AKIAJ7SN435435CGBIEEB3CRLA"; 
$AWS_s3_secret_key="dJnfWNcKY2A45435ddT4W0NduCdg7+voVnDialbF0dvgr"; 
$expire_seconds="1000";



     $expires = time()+$expire_seconds;
     // S3 Signed URL creation
     $string_to_sign = "GET\n\n\n{$expires}\n/".str_replace("s3.ap-south-1.amazonaws.com","", $bucket)."/$folder"."/$resource";
     $signature = urlencode((hash_hmac("sha256", utf8_encode($string_to_sign), $AWS_s3_secret_key, TRUE)));



     $authentication_params = "AWSAccessKeyId=".$AWS_S3_KEY;
     $authentication_params.= "&Expires={$expires}";
     $authentication_params.= "&Signature={$signature}";
     return $link = "https://s3.ap-south-1.amazonaws.com/{$bucket}/{$folder}/{$resource}?{$authentication_params}";

When i hit api to get access the file from s3 storage .I got issue

InvalidRequest The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256. Id>85DAE9708BDF8514 zjhhQ+iJ3q3z8goBtMdRLfTdla5QAqaFCqQCdIRVxVjdWtykam3+NzNv/+gMgPmepTLkyi9So+c=

But am using AWS4-HMAC-SHA256 authorization mechanism to access the file.I dont know where am wrong .kindly help me for this problem.

sakthi
  • 1
  • 4
  • Amazon has a [PHP SDK](https://aws.amazon.com/sdk-for-php/) you can use to do these things. – apokryfos May 25 '17 at 13:47
  • Hi @apokryfos , I tried all my efforts last two days for this problem , The above post established the my code and my error . – sakthi May 25 '17 at 14:02
  • Well obviously the error says that your signature is invalid based on your request, which makes sense because typically people sign the full URL instead of the full request header. At any rate, the SDK would take care of this for you so you don't have to spend another 2 days on it – apokryfos May 25 '17 at 14:04
  • Ok but one more think the error say Please use ** AWS4-HMAC-SHA256** but i used that mechanism only.I think the error occur there only – sakthi May 25 '17 at 14:08
  • `AWS4-HMAC-SHA256` is a constant within the AWS SDK so that's not what you are actually using. Check http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html – apokryfos May 25 '17 at 14:10
  • Laravel comes out of the box with `Flysystem` which supports AWS S3. I personally use this and it's a breeze. https://laravel.com/docs/5.3/filesystem#driver-prerequisites – Sandeesh May 25 '17 at 15:05
  • Hi @Sandeesh am currently using **Flysystem** for ASW S3 but my question is , i Uploaded via file in private mode into s3 storage and i need to access the file with some time (expiry 1 min) when i hit for get object .... – sakthi May 25 '17 at 15:38
  • Thankyou @apokryfos for your concern , I just looked and studied aws amazon document and generated policy but it couldn't workout for my needs. – sakthi May 25 '17 at 15:39
  • You are *clearly* not using AWS**4**-HMAC-SHA. This is Signature Version 2, not V4. – Michael - sqlbot May 25 '17 at 22:47
  • Hi @Michael-sqlbot , Thank you for your suggestion.Could you help more about on AWS4-HMAC-SHA mechanism signature version V4. – sakthi May 26 '17 at 04:51
  • The first link in my answer to [The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256](https://stackoverflow.com/a/26538266/1695906) is to the S3 signing process for Signature Version 4, which is the only mechanism supported in regions where S3 was first deployed in 2014 or later. – Michael - sqlbot May 26 '17 at 10:31
  • @Michael-sqlbot , Currently am using the mumbai region for storage – sakthi May 26 '17 at 10:37
  • Mumbai has been [online since 2016](https://aws.amazon.com/blogs/aws/now-open-aws-asia-pacific-mumbai-region/), which means that Mumbai only supports Signature Version 4, the same as Frankfurt, London, Ohio, and all newer regions. Your code uses Signature Version 2. It is easy to visually tell them apart, becase V2 has `AWSAccessKeyId=...&Signature=...`, while V4 has `X-Amz-Credential=...&X-Amz-Signature=...` in the URL patterns. – Michael - sqlbot May 26 '17 at 10:49
  • @Michael-sqlbot , Could you help me more on code for Amazon version v4 – sakthi May 26 '17 at 11:57

0 Answers0