bryan
bryan

Reputation: 9389

Using Appengine, connect to a different Google Cloud Storage

So I have 2 app engine projects.

In one of my app engines, I have a google cloud storage component with it. Usually to connect to those cloud storage files I just do:

<?php
   use google\appengine\api\cloud_storage\CloudStorageTools;

   $document_data = "123";
   $object_url = 'gs://{bucket}/FOLDER/file.ext';
   $options = stream_context_create(['gs'=>['acl'=>'private']]);
   $my_file = fopen($object_url, 'w', false, $options);
   fwrite($my_file, $document_data);
   fclose($my_file);
?>

or

<?php file_get_contents('gs://FOLDER/file.ext'); ?>

I have another app engine with no google cloud storage but i'd like to connect to the cloud storage in my other app engine.

Does anyone know how I could do that?

Upvotes: 1

Views: 130

Answers (1)

Adri&#225;n
Adri&#225;n

Reputation: 2880

You need to give bucket permissions to the App Engine application as follows:

  1. Go to the Storage browser section in the Developers Console.
  2. Select your bucket, click on the 3 vertical dots and click on 'Edit bucket permissions'.
  3. Click on 'Add new', select 'User' and select at least WRITER permissions. Type your App Engine service account in the text field. The App Engine service account has the format: <projectID>@appspot.gserviceaccount.com

  4. Save the changes.

After these steps you should be able to connect to a bucket that belongs to another project.

Upvotes: 4

Related Questions