I upload files from php download to s3 bucket.its, but when I get the image, I get the following error.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<Expires>2006-03-09T07:25:20Z</Expires>
<ServerTime>2016-11-05T04:38:24Z</ServerTime>
if I set the publication when downloading files, then I can get it, but I wanted to protect it from unauthorized users.
upload file code
try{
$s3 = \Storage::disk('s3');
$filePath = $file->getClientOriginalName();
$s3->put($filePath, file_get_contents($val), 'private');
} catch (Aws\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n"+$e;
}
Before asking a question, I refereed many sites, but this did not help me
Amazon S3 see personal files
PHP Amazon S3 accesses private files via URL
How to access Amazon s3 private slave through Zend_Service_Amazon_S3
The third link works for me, but
1. Is it safe to pass the passkey in the URL?
2.can view this file for authenticated user?
public function get_s3_signed_url($bucket, $resource, $AWS_S3_KEY, $AWS_s3_secret_key, $expire_seconds) {
$expires = time()+$expire_seconds;
// S3 Signed URL creation
$string_to_sign = "GET\n\n\n{$expires}\n/".str_replace(".s3.amazonAWS.com","", $bucket)."/$resource";
$signature = urlencode(base64_encode((hash_hmac("sha1", 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 = "http://s3.amazonAWS.com/{$bucket}/{$resource}?{$authentication_params}";
}