如何在amazons3上获得正确的图像路径

I'm using the following code to get the path of images on S3

Storage::getDriver()
                ->getAdapter()
                ->getClient()
                ->getObjectUrl(env('S3_BUCKET_NAME'), $key);

this url returns BUCKETNAME.s3-eu-west-1-amazon.com/$key

while the real url of the image is s3-eu-west-1-amazon.com/BUCKETNAME/$key

what to do get the same url ?

Amazon S3 supports 2 types of object URLs:

  • path style: $host/$bucket/$key
  • virtual host style: $bucket.$host/$key

You can find more information about them here: http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro

The URL you're getting from the client should work regardless of the format. The format used depends on:

  • format of the endpoint client is using - IPs result in path style URLs
  • bucket name - some bucket names are not valid DNS names and will result in path-style as well