1

Shai from codename one helped me to upload an image to s3 bucket and I am able to upload images and I happen to notice that when I access the image from browser I am getting Access denied error.

The image was loading fine on the mobile app, the same image throws Access denied error in the web browser.

this is my code:

   String strImage = Capture.capturePhoto(width, -1);
   String s3Bucket = "https://s3.amazonaws.com/MyBuckt/";
   String fileName = "Images/1234567";
   MultipartRequest rq = new MultipartRequest();
   rq.setUrl(s3Bucket);
   rq.addArgumentNoEncoding("key", fileName);
   rq.addArgument("acl", "public-read-write"); // here I give read-write access
   rq.addData("file", strImage, "image/jpeg");
   NetworkManager.getInstance().addToQueue();

When I launched S3 Browser and I do see the file and when I click on the file I get Access denied pop up message. The bucket and the folder has been given full grant permission as well as sub folders.

  • The image is captured by the phone camera.

Any help is appreciated.

Ravimaran
  • 431
  • 1
  • 3
  • 10
  • Maybe the directory or the bucket itself have a restriction on who can view them? – Shai Almog May 06 '17 at 05:13
  • Hi Shai, thank you for the response. All users have the read and write permission to the folder and as well as for the bucket too. By selecting the file in in S3 Browser there is no permissions checked. I dragged and drop a file in the folder and I do see the permission checked. Not sure what to do now. Any help will be much appreciated. Thank you. – Ravimaran May 06 '17 at 16:45

1 Answers1

1

After doing some research, I have found the solution for it. Hopefully it may help someone. Solution:

   String strImage = Capture.capturePhoto(width, -1);
   String s3Bucket = "https://s3.amazonaws.com/MyBuckt/";
   String fileName = "Images/1234567";
   MultipartRequest rq = new MultipartRequest();
   rq.setUrl(s3Bucket);
   rq.addArgumentNoEncoding("key", fileName);
   //rq.addArgument("acl", "public-read-write"); // here I give read-write access
   rq.addArgument("acl", "bucket-owner-full-control");
   rq.addData("file", strImage, "image/jpeg");
   NetworkManager.getInstance().addToQueue();

I modified the acl access level as follows

rq.addArgument("acl", "bucket-owner-full-control");

What I understood from the readings, the uploaded item will not have any access except delete. With this acl access the file is now can be read.

Link that I got the info from: https://stackoverflow.com/questions/34055084/s3-user-cannot-access-object-in-his-own-s3-bucket-if-created-by-another-user

** Thank you Shai for being very responsive and be helpful as much as you can **

Community
  • 1
  • 1
Ravimaran
  • 431
  • 1
  • 3
  • 10