How do I enable Google Cloud Storage on my local development server?

前端 未结 4 1578
执笔经年
执笔经年 2021-01-02 00:18

I want to use a GCS bucket as the backing for my blobstore but I cannot figure out how to set one up on my development server.

There are instructions for doing this

4条回答
  •  不思量自难忘°
    2021-01-02 00:38

    Figured this could use some more recent findings. For me, the local cloud storage doesn't work at all. It fails with an error saying GsFileInfo is a protected entity. It works fine if you don't fire up the local datastore emulator (meaning it uses the remote cloud storage).

    This seems to jive with google's latest docs: https://cloud.google.com/appengine/docs/standard/java/using-cloud-storage#using_cloud_storage_with_the_local_development_server

    The App Engine local development server doesn't emulate Cloud Storage, so all Cloud Storage requests must be sent over the Internet to an actual Cloud Storage bucket.

    Thus the answer from @learnj12 is the best approach. However the GoogleCredential has been deprecated, and it's unclear how to implement com.google.appengine.tools.cloudstorage.oauth.AccessTokenProvider.

    Here's what worked for me:

    import com.google.appengine.api.appidentity.AppIdentityService;
    import com.google.appengine.api.appidentity.AppIdentityServiceFactory;
    import com.google.appengine.tools.cloudstorage.oauth.AccessTokenProvider;
    
    public class GCSTokenProvider implements AccessTokenProvider {
      @Override
      public AppIdentityService.GetAccessTokenResult getNewAccessToken(List list) {
        return AppIdentityServiceFactory.getAppIdentityService().getAccessToken(Collections.singleton("cloud-platform"));
      }
    }
    

    NB. I'm using a service account, and am logged in with gcloud.

提交回复
热议问题