Google App engine Java API writte in bucket on local dev server doesn't work

234 Views Asked by At

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.

2

There are 2 best solutions below

2
jarmod On

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.

2
Benjyyyyy On

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.