1
votes

this is the error i get Error executing "PutObject" on "https://s3.ap-south-1.amazonaws.com/infosecure.buck/uploads/5th.jpg"; AWS HTTP error: Client error: PUT https://s3.ap-south-1.amazonaws.com/infosecure.buck/uploads/5th.jpg resulted in a 403 Forbidden response: AccessDeniedAccess Denied69DC61 (truncated...) AccessDenied (client): Access Denied - AccessDeniedAccess Denied69DC6155E0F5042AHg2jvV2iLEsOHnmsvxM2meASpYr9Z3I6zPxEPedneHixIaPZpfESW1/SCO0UwlVnTKBXwkatE0M=

<?php
use Aws\S3\Exception\S3Exception;

require 'app/start.php';

if(isset($_FILES['file']))
{
   $file=$_FILES['file'];

  $name= $file['name'];

  $tmp_name = $file['tmp_name'];

  $extension = explode('.',$name);

  $extension=strtolower(end($extension));

  $key = md5(uniqid());

  $tmp_file_name= "{$key}.{$extension}";
  $tmp_file_path = "files/{$tmp_file_name}";
  move_uploaded_file($tmp_name,$tmp_file_path);
  try{

     $s3->putObject([
     'Bucket' => $config['s3']['bucket'],
     'Key' => "uploads/{$name}",
     'Body' => fopen($tmp_file_path,'rb'),
     'ACL' => 'public-read'

     ]); 

  unlink($tmp_file_path);}
  catch(S3Exception $e)
  {
      echo $e->getmessage();
  }




}
?>

this is my bucket policy

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::601825519382:user/admin-infosecure" }, "Action": "s3:*", "Resource": "arn:aws:s3:::infosecure.buck" } ] }

2
what's the error? what are you trying to do?Yeshodhan Kulkarni
i'm trying to upload files to s3 using php. and sorry about adding code i'm not able to add any code it says your post mostly contains codeGd Viper
there will be something more after 'PUT ..... Do you mind adding it to the question? adding some more context to the question like a code snippet will also go a long way.Yeshodhan Kulkarni
yeah there is but the title limits me only to 150 chractersGd Viper
now i've added itGd Viper

2 Answers

1
votes

Seems to be a permission issue.

If you are accessing via a local machine, make sure your IAM user has write access to the bucket.

If you are running this code on an EC2 instance, make sure the Instance Role has write access to this bucket.

0
votes

For PutObject / GetObject the ARN needs to refer to the objects within the bucket, so instead of:

{
  "Version": "2012-10-17"
, "Statement": [ {
    "Effect": "Allow"
  , "Principal": { "AWS": "arn:aws:iam::601825519382:user/admin-infosecure" }
  , "Action": "s3:*"
  , "Resource": "arn:aws:s3:::infosecure.buck" 
  } ] 
}

You want

{
  "Version": "2012-10-17"
, "Statement": [ {
    "Effect": "Allow"
  , "Principal": { "AWS": "arn:aws:iam::601825519382:user/admin-infosecure" }
  , "Action": "s3:*"
  , "Resource": [
      "arn:aws:s3:::infosecure.buck"
    , "arn:aws:s3:::infosecure.buck/*" 
    ]
  } ] 
}