谷歌云存储检查对象是否存在(App Engine Java) [英] google cloud storage check if object exists (App Engine Java)

查看:37
本文介绍了谷歌云存储检查对象是否存在(App Engine Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

My AppEngine project has an API method that sends a resumable URL to an Android Client which then uses that resumable URL to upload an image.

I have another API method that create and returns a signed URL. In the Signed URL you must specify the Google Cloud Storage bucket and object name. However, that object may not exist, in which case, the signed URL will of course not work.

How can I quickly check if an object exists (in a bucket) in my App Engine backend before issuing the Signed URL?

EDIT: My App Engine project is a Cloud Endpoints project.

解决方案

You can call getMetadata to check if the object exists without downloading it.

GcsService fileService = GcsServiceFactory.createGcsService();
GcsFilename file = new GcsFilename(bucket, object);
fileService.getMetadata(file);

Alternatively, you can list all objects in a bucket or all objects in a bucket that start with the specified prefix (which can equal the object's name, if necessary).

UPDATE:

This is how I send uploadURL to my client:

@Override
public String getUploadUrl() throws LoginException, VersionException {
    // Verify that call is from a registered user and with proper headers

    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    String callbackUrl = "/blob";
    return blobstoreService.createUploadUrl(callbackUrl,
           UploadOptions.Builder.withGoogleStorageBucketName("myBucket));
}

这篇关于谷歌云存储检查对象是否存在(App Engine Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆