How do I access Google Cloud Storage from App Engine in an on-premises development environment?

My code works fine on deployed Google App Engine, but not when debugging it locally. The return value of GcsFileMetadata is null, and gcsService.openReadChannel (gcsFilename, 0) gives a FileNotFoundException, more details below. To summarize, the problem is that the local engine of the application cannot access google cloud storage. How to fix it? Any workarounds?

Here's the code

GcsFilename gcsFilename = new GcsFilename(BUCKET_NAME, progress.imageName);

GcsFileMetadata gcsFileMetadata = gcsService.getMetadata(gcsFilename);

if (gcsFileMetadata == null) throw new Exception("gcsService.getMetadata(gcsFilename) returned null");

int fileSize = (int) gcsFileMetadata.getLength();

ByteBuffer byteBuffer = ByteBuffer.allocate(5*1024*1024);
GcsInputChannel gcsInputChannel = gcsService.openReadChannel(gcsFilename, 0);
gcsInputChannel.read(byteBuffer);

      

gcsFileMetadata is null when debugging locally, but works fine when deployed. I will comment this out and I am getting the following error on this line:

GcsInputChannel gcsInputChannel = gcsService.openReadChannel(gcsFilename, 0);

Here's the error:

java.io.FileNotFoundException: com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService@54381103: No such file: GcsFilename(cloudimagesbucketname, image_20150105_180444)

      

+3


source to share


1 answer


There is no workaround to access google cloud storage on localhost. You have to deploy your code to appengine and only then can you access the GCS services. This is a secure service from google that cannot be accessed on localhost.



+1


source







All Articles