2

I've GAE application which creates some data in the Google Cloud Datastore and stores some binary files into the Google Cloud Storage - let's call the application WebApp. Now I have a different application running on the Google compute engine. Let's call the application ComputeApp.

The ComputeApp is a backend process which is processing data created by the WebApp. I asked here in this question previously which API can I use to communicate with Storage from the ComputeApp. I implemented the Storage communication using of the Google Cloud Storage JSON API Client Library for Java.

Everything works fine as far as I'm communicating with the Storage in the Google cloud. I'm using the service account authentication.

Now I need to run my ComputeApp locally, in my development PC so I'll take data created by my local WebApp and stored into the local debug Storage. I need it because I want to have a testing environment so I can debug may app locally. My WebApp running locally stores binary data to the local Datastore. I can see it through the local admin console: (localhost:8080/_ah/admin). There is list of entities GsFileInfo and a list of the __ah_FakeCloudStorage... entities, representing my storage data.

How should I modify my ComputeApp code to force it to connect to my local debug Storage and access these binary data stored locally instead of connect to the Google cloud?

Community
  • 1
  • 1
Fipil
  • 291
  • 2
  • 5
  • 16

1 Answers1

0

Create account in Google Project Console, and Service account credentials

Initialize:

private static final String APPLICATION_NAME = "your-webapp";
      private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

       GoogleCredential credential = GoogleCredential.getApplicationDefault();
              if (credential.createScopedRequired()) {
                credential = credential.createScoped(StorageScopes.all());
              }
              HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
              storageService = new Storage.Builder(httpTransport, JSON_FACTORY, credential)
                  .setApplicationName(APPLICATION_NAME).build();



   InputStreamContent mediaContent = new InputStreamContent(contentType, inputStream);


    StorageObject objectMetadata = null;
      objectMetadata = new StorageObject()
          .setName(name)
          .setMetadata(ImmutableMap.of("date", new Date().toString()))
          .setAcl(ImmutableList.of(
             new ObjectAccessControl().setEntity("allUsers").setRole("READER")

              ))
          .setContentDisposition("attachment");


    Storage.Objects.Insert insertObject = storageService.objects().insert("staging.your-app.appspot.com", objectMetadata,
        mediaContent);


    // For small files, you may wish to call setDirectUploadEnabled(true), to
    // reduce the number of HTTP requests made to the server.
    if (mediaContent.getLength() > 0 && mediaContent.getLength() <= 2 * 1000 * 1000 /* 2MB */) {
      insertObject.getMediaHttpUploader().setDirectUploadEnabled(true);
    }

    insertObject.execute();
Jeryl Cook
  • 989
  • 17
  • 40