0

I use GCSService for writting file in a GoogleCloudStorage bucket, all works fine with online instance, but when I want to test my code on my local dev server, it's impossible to writte in a bucket (an emulate local bucket like for datastore). Additional difficulty I try to write on my local server with remote API from fat client, i search all around the web I doesn't find my answer. When I call my createOrUpdate() method I have this exception :

com.google.appengine.tools.cloudstorage.NonRetriableException: java.lang.RuntimeException: Server replied with 403, verify ACLs are set correctly on the object and bucket: Request: POST https://storage.googleapis.com/InstanceName/FileInfos

It's seem to try to write on my online bucket...

GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
...
RemoteApiOptions destination = RemoteConnection.connect(destinationServer);
RemoteApiInstaller destinationInstaller = new RemoteApiInstaller();
destinationInstaller.install(destination);
try
{
    GcsOutputChannel outputChannel = gcsService.createOrReplace(new GcsFilename(destinationBucketServer, fileInfo.getFilename()),
            GcsFileOptions.getDefaultInstance());

    outputChannel.write(ByteBuffer.wrap(data));
    outputChannel.close();
}
catch (Exception e)
{
    ....
}
finally
{
    buffer.flush();
    destinationInstaller.uninstall();
}

With same code I can write in DataStore without any problem, it's only a Storage issues.

Adam Arold
  • 29,285
  • 22
  • 112
  • 207
Benjyyyyy
  • 33
  • 5

2 Answers2

1

See the Google Cloud Storage Errors and Error Handling and Service Account docs.

403 indicates that the user was not authorized to make the request. When running on your GCE instance, I'm guessing that your code is running in a service account that has write permissions to your bucket. When running locally, you will have to provide appropriate credentials to do the same.

jarmod
  • 71,565
  • 16
  • 115
  • 122
  • Yes I know what 403 means, but where i can configure local ACL for local bucket, I don't find anything about this configuration. In the exception there is distant url POST https://storage.googleapis.com/InstanceName/FileInfos like it try to upload online. Thanks for answering – Benjyyyyy Jun 13 '16 at 08:05
  • In addition to that I use development server credential for connect to my local server, what i missed here? Why this code doesn't provide access? new RemoteApiOptions().server(server.getAddress(), server.getPort()).useDevelopmentServerCredential(); – Benjyyyyy Jun 13 '16 at 09:26
0

I figured out why this isn't works, in fact call GCS through RemoteAPI doesn't write on local server, it write on online bucket. That's why I didn't have right ACL, my code try to connect to Cloud Storage. But now i don't know how to force GCSService to write on my local server.

Benjyyyyy
  • 33
  • 5
  • App Engine supports Datastore emulation. Are you sure it supports Cloud Storage emulation? – jarmod Jun 20 '16 at 13:44
  • Yes it supports Cloud Storage emulation, when you use GCSService in local context. In my case we try to write in local Cloud storage through RemoteAPI, in this context it is not working – Benjyyyyy Jun 22 '16 at 09:03