The Google Java API write-in bucket engine on the local dev server does not work

advertisements

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.


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.