尝试getServingUrl存储在GCS中的图像时OBJECT_NOT_FOUND [英] OBJECT_NOT_FOUND when trying to getServingUrl of an image stored in GCS
问题描述
我已经写了一个Servlet,用于从 blobstore
(来自GCS的另一个图像)读取图像,然后在这两个图像上应用合成后,我将合成图像回到GCS。
我的代码运行良好,直到这里。
之后,当我尝试获取合成图像的服务URL时,我得到 OBJECT_NOT_FOUND
。
为了试验,我手动上传了GCS中的图片,并给了所有必要的权限。添加了作为OWNER的serviceaccount,并授予所有用户的READ访问权限。然后,我再次尝试获取服务网址。以下是我的代码: - $ /
$ b $ pre $ BlobKey newImageKey = blobstoreService.createGsBlobKey(gcsPath);
//log.severe(\"GCS PATH:+ gcsPath +BlobKey:+ newImageKey);
ServingUrlOptions选项= ServingUrlOptions.Builder.withBlobKey(newImageKey);
字符串profilePicLink = imgService.getServingUrl(options);
我也尝试了下面的代码: - $ /
ServingUrlOptions选项= ServingUrlOptions.Builder.withGoogleStorageFileName(gcsPath);
字符串profilePicLink = imgService.getServingUrl(options);
在这两种情况下,这都是我得到的错误:
/ controller javax.servlet.ServletException:
java.lang.IllegalArgumentException:OBJECT_NOT_FOUND:
顺便说一句,我没有启用计费,因为我正在使用带有免费配额的默认存储桶。这还在开发中,所以免费配额适用于我。
好的,我找到了发生异常的位置......
request.build()。toByteArray());
以及抛出的异常是:
ApiProxy.ApplicationException应用程序错误8
启用结算和尝试过,仍然没用:(b / b)
一直试图解决这一整天,并试图在任何地方搜索解决方案。
如果在GCSFileOptions中添加.acl(public-read )。
一旦ac l通过以上两种方法之一应用,在GCS云控制台中,您可以看到图像共享公开链接复选框以短划线形式出现,并且表示您没有权限编辑权限。看到它我感到困惑,因为我期待复选框被检查。
但即使在上述情况下,公共共享链接也可以正常工作: -
http://storage.googleapis.com/ [bucket_name] / [gcs_object_name]
如果有人能解释为什么getServingUrl不起作用,我仍然会很感激。是的,它仍然没有工作后设置默认acl读。
谢谢,
Sukalpo。
I have written a Servlet where I am reading an image from blobstore
, another image from GCS and then after applying a composite on both these images I am storing the composite image back in GCS.
My code works well till here.
After that, when I am trying to get the serving url for the composite image, I am getting an OBJECT_NOT_FOUND
.
Just to experiment I manually uploaded a image in GCS and gave all the necessary permissions. Added the serviceaccount as OWNER and gave READ access to All users. And then again I am just trying to get the serving url. Following is my code:-
BlobKey newImageKey = blobstoreService.createGsBlobKey(gcsPath);
//log.severe("GCS PATH: " + gcsPath + " BlobKey: " + newImageKey);
ServingUrlOptions options = ServingUrlOptions.Builder.withBlobKey(newImageKey);
String profilePicLink = imgService.getServingUrl(options);
I also tried the below code:-
ServingUrlOptions options = ServingUrlOptions.Builder.withGoogleStorageFileName(gcsPath);
String profilePicLink = imgService.getServingUrl(options);
And in both the cases this is the error that I am getting:
/controller javax.servlet.ServletException: java.lang.IllegalArgumentException: OBJECT_NOT_FOUND:
Btw, I have not enable billing as I am using the default bucket with the free quota. This is still in development so the free quota works for me.
OK, so I found out where exactly the exception is happening...
byte[] responseBytes = ApiProxy.makeSyncCall(PACKAGE, "GetUrlBase", request.build().toByteArray());
and the exception it is throwing is :
ApiProxy.ApplicationException Application Error 8
Enabled billing and tried, still of no use :(
Have been trying to solve this the whole day and tried to search a solution everywhere.
Though this actually does not answer my original question but I have found a workaround. I installed python and gsutil and set the default acl of my bucket to read. Now when I am saving an image file in GCS I am just showing the public url link.
The above can also be achieved if in the GCSFileOptions we add .acl("public-read").
Once the acl is applied by either of the above two methods, in the GCS cloud console you can see the images shared publicly link check box comes as a dash and it says you do not have permission to edit permissions. I was getting confused seeing it, as I was expecting the checkbox to be checked.
But even in the above scenario the publicly shared link will work which is:-
http://storage.googleapis.com/[bucket_name]/[gcs_object_name]
I would still appreciate if someone can explain why the getServingUrl is not not working. Yes, it is still not working after set default acl to read.
Thanks, Sukalpo.
这篇关于尝试getServingUrl存储在GCS中的图像时OBJECT_NOT_FOUND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!