[英]How to generate reference url for Google Cloud Storage image objects using java
I want to generate an URL for accessing the images in the bucket in Google Cloud Storage, as I want to reference it in img src tag of html. 我想生成一个用于访问Google Cloud Storage存储桶中图像的URL,因为我想在html的img src标签中引用它。 The reason is that we don't store the image in server. 原因是我们没有将图像存储在服务器中。
How can I achieve the following using java? 如何使用Java实现以下目标?
https://storage.cloud.google.com/my-bucket-name/myImage.jpg
. 生成URL以引用我的Google Cloud Storage存储桶中的图像https://storage.cloud.google.com/my-bucket-name/myImage.jpg
。 But what I observed is when I paste the above url in the browser, I find that the URL gets changed to some random url like below, and with this below url anybody can view the image without sign in and I feel if I could generate this URL using java I may be able to resolve the problem. 但是我观察到的是,当我将上面的URL粘贴到浏览器中时,我发现URL变为如下所示的一些随机URL,有了这个URL,任何人都可以查看图像而无需登录,我觉得我可以生成此图像使用java的URL我也许可以解决问题。
URL is as below (random fake URL) 网址如下(随机伪造网址)
https://00e9e544fb-apidata.googleusercontent.com/download/storage/v1/b/my-bucket-name/o/myImage.jpg?qk=AD5-vreOG-Y-RsJ0DZuI--owy_O_cx1RQy_Ya_kn0A_T-iT-3xhg
Your original suggestion, https://storage.cloud.google.com/my-bucket-name/myImage.jpg
, should be fine, but for it to work without any authentication, you'll need to grant read permission for those objects to anonymous users. 您最初的建议https://storage.cloud.google.com/my-bucket-name/myImage.jpg
应该可以,但是要使其在没有任何身份验证的情况下工作,您需要为这些对象授予读取权限匿名用户。
For instructions on that, see Allow Public Read access on a GCS bucket? 有关说明,请参阅在GCS存储桶上允许公共读取访问? . 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.