我使用以下方法在Google云端存储上上传的图像文件上创建了一个imageServing网址:
String key = "/gs/<bucket-name>/<path>";
ImagesService imagesService = ImagesServiceFactory.getImagesService();
ServingUrlOptions options = ServingUrlOptions.Builder
.withGoogleStorageFileName(key)
.imageSize(900) // Optional.
.crop(true); // Optional.
String servingUrl = imagesService.getServingUrl(options);
但似乎没有删除此网址的方法。 可用方法&#34; deleteServingUrl&#34;接受一个我不使用的blobKey。
这是否意味着我不需要删除servingUrl?
/////// EDIT
使用Appengine与客观化。 创建了一个servlet,UserImageEndpoint 在web.xml中将其定义为:
<servlet>
<servlet-name>UserImageEndpoint</servlet-name>
<servlet-class>reach.backend.Servlets.UserImageEndpoint</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserImageEndpoint</servlet-name>
<url-pattern>/userImageEndpoint</url-pattern>
</servlet-mapping>
Servlet类:
public class UserImageEndpoint extends HttpServlet {
private static final Logger logger = Logger.getLogger(UserImageEndpoint.class.getName());
private static final String BUCKET_NAME_IMAGE = "xxxx-yyyy";
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//
//
//
GcsFilename gcsFilename = new GcsFilename(BUCKET_NAME_IMAGE, actualImageId);
GcsService gcsService = GcsServiceFactory.createGcsService();
//this works, I get the meta-data, hence I am able to access
logger.info(gcsService.getMetadata(gcsFilename).toString());
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobstoreService.createGsBlobKey(
"/gs/" + gcsFilename.getBucketName() + "/" + gcsFilename.getObjectName());
logger.info("Requesting fileName - " + blobKey.getKeyString());
servingURL = ImagesServiceFactory.getImagesService().getServingUrl(
ServingUrlOptions.Builder.withBlobKey(blobKey));
最后一行崩溃:
java.lang.IllegalArgumentException:ACCESS_DENIED:at com.google.appengine.api.images.ImagesServiceImpl.getServingUrl(ImagesServiceImpl.java:282)
////// EDIT 凌没有。 282似乎是方法deleteServingUrl(BlobKey blobKey),我现在甚至没有调用...
答案 0 :(得分:1)
正如@konqi指出文档中的重要部分所述,如果该文件已通过云存储公开发布,则无法获取服务URL(cloud.google.com/appengine/docs/java/images )
我遇到了完全相同的问题,但是在尝试使用Blobstore API创建服务URL之前,未通过在云存储中将ACL设置为public来解决此问题。