简体   繁体   English

如何在Amazon3上获取正确的图像路径

[英]how to get the correct image path on amazons3

I'm using the following code to get the path of images on S3 我正在使用以下代码来获取S3上图像的路径

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

this url returns BUCKETNAME.s3-eu-west-1-amazon.com/$key 此网址返回BUCKETNAME.s3-eu-west-1-amazon.com/$key

while the real url of the image is s3-eu-west-1-amazon.com/BUCKETNAME/$key 而图片的实际网址是s3-eu-west-1-amazon.com/BUCKETNAME/$key

what to do get the same url ? 如何获得相同的网址?

Amazon S3 supports 2 types of object URLs: Amazon S3支持两种类型的对象URL:

  • path style: $host/$bucket/$key 路径样式: $ host / $ bucket / $ key
  • virtual host style: $bucket.$host/$key 虚拟主机样式: $ bucket。$ host / $ key

You can find more information about them here: http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro 您可以在此处找到有关它们的更多信息: 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. 不管格式如何,从客户端获取的URL都可以使用。 The format used depends on: 使用的格式取决于:

  • format of the endpoint client is using - IPs result in path style URLs 端点客户端使用的格式-IP生成路径样式的URL
  • bucket name - some bucket names are not valid DNS names and will result in path-style as well 值区名称-某些值区名称不是有效的DNS名称,也会导致路径样式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM