开发者

Amazon S3 Access image by url

I have uploaded an image to Amazon S3 storage. But how can I access this image by url? I have made the folder and file public but still get AccessD开发者_JAVA百科enied error if try to access it by url https://s3.amazonaws.com/bucket/path/image.png


This is an older question, but for anybody who comes across this question, once I made the file public I was able to access my image as https://mybucket.s3.amazonaws.com/myfolder/afile.jpg


in my case i have uploaded image privately so that i was unable to access. i did following code

const AWS = require('aws-sdk')
const myBucket = 'BUCKET_NAME'
  const myKey = 'FILE_NAME.JPG'
  const signedUrlExpireSeconds = 60 * 1
  const s3 = new AWS.S3({
    accessKeyId: "ACCESS_KEY_ID",
    signatureVersion: 'v4',
    region: 'S3_REGION',
    secretAccessKey: "ACCESS_SECRET"
  });

  const url = s3.getSignedUrl('getObject', {
      Bucket: myBucket,
      Key: myKey,
      Expires: signedUrlExpireSeconds
  })

  console.log(url)


You can access your image by using:

https://s3.amazonaws.com/bucketname/foldername/imagename.jpg

or if there are no folders, you can do:

https://s3.amazonaws.com/bucketname/imagename.jpg

upvote if helps. It conforms to present AWS dated 30 may 2017.


Seems like you can now simply right-click on any folder inside a bucket and select 'Make Public' to make everything in that folder public. It may not work at the bucket level itself.


One of easiest way is to make a bucket policy.

 {
       "Version": "2012-10-17",
       "Statement": [{
           "Sid": "MakeItPublic",
           "Effect": "Allow",
           "Principal": "*", 
           "Action": "s3:GetObject",
           "Resource": "arn:aws:s3:::yourbucketname.com/*"
    }]
   }


make sure you access image using the same case as it was uploaded and stored on S3. for example, if you uploaded image_name.JPG, you should use the same name, but not image_name.jpg


For future reference, if you want to access a file in Amazon S3 the URL needs to be something like:

bucketname.s3.region.amazonaws.com/foldername/image.png

Example: my-awesome-bucket.s3.eu-central-1.amazonaws.com/media/img/dog.png

Don't forget to set the object to public.

Inside S3 if you click on the object will you see a field called: Object URL. That's the object's web address.


On your console, right click on the image you want to access and click on "Make Public"; when thats done right click on the image again and click on "Properties" and copy the Link from the Extended view.


I came across this question whilst looking for a solution to a similar problem with being unable to access images.

It turns out that images with a % in their filename, when being accessed, must have the % symbol URL encoded to %25.

i.e. photo%20of%20a%20banana%20-%2019%20june%202016.jpg needs to be accessed via photo%2520of%2520a%2520banana%2520-%252019%2520june%25202016.jpg.

However, URL encoding the full path didn't work for us, since the slashes, etc would be encoded, and the path would not work. In our specific case, simply replacing % with %25 in all access paths made the difference.


Just add Permission to follow the below image.

Amazon S3 Access image by url


I was having the same problem. I have the issue the spacing in image url. I did this to make it work:

String imgUrl=prizes.get(position).getImagePreview().replaceAll("\\s","%20");

now pass this url to picasso:

Picasso.with(mContext)
            .load(imgUrl)
            .into(mImageView);


To access private images via URL you must provide Query-string authentication. Query-string authentication version 4 requires the X-Amz-Algorithm, X-Amz-Credential, X-Amz-Signature, X-Amz-Date, X-Amz-SignedHeaders, and X-Amz-Expires parameters.


Just addon to @akotian answer, you can get the object URL by clicking the object as follows

Amazon S3 Access image by url

and to access publically you can set the ACL programmatically while uploading the object to the bucket

i.e sample java request

PutObjectRequest putObjectRequest = PutObjectRequest.builder()
            .contentType(contentType)
            .bucket(LOGO_BUCKET_NAME)
            .key(LOGO_FOLDER_PREFIX+fileName)
            .acl(ObjectCannedACL.PUBLIC_READ)// this make public read
            .metadata(metadata)
            .build();


{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicRead",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectVersion"
            ],
            "Resource": [
                "arn:aws:s3:::DOC-EXAMPLE-BUCKET/*"
            ]
        }
    ]
}

use this policy for that bucket, which makes it public.


Adding bucket policy worked for me

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::yourbucketname/*"
        }
    ]
}


Turn off Block public access (bucket settings) from Permissions tab inside your bucket. You also need to Edit the permissions of the object. Provide Read access on Grantee Everyone (public access). Then chech "I understand the effects of these changes on this object." and Save changes.


Change your Bucket.. It may works

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜