0
votes

I am attempting to use Google AppEngine with my app (to replace AWS). I have the datastore working with the following code:

themeendpoint.Builder endpointBuilder = new themeendpoint.Builder(
            AndroidHttp.newCompatibleTransport(),
            new JacksonFactory(),
            new HttpRequestInitializer() {
                public void initialize(HttpRequest httpRequest) { }
            });

    themeendpoint endpoint = CloudEndpointUtils.updateBuilder(
            endpointBuilder).build();
    DbAdapter dbAdapter = new DbAdapter(mCtx);
    try {
        CollectionResponseTheme response = endpoint.listTheme().execute();        
        List<Theme> listResponse = response.getItems();
...

However, when I try to use the following code for the Cloud Storage API (added using Eclipse-->Google-->Add Google APIs) to download a zip file that I have stored:

File file = new File(Environment.getExternalStorageDirectory() + mLocalPath + mZipName);

    Builder storageBuilder = new Storage.Builder(AndroidHttp.newCompatibleTransport(),
            new JacksonFactory(),
            new HttpRequestInitializer() {
                public void initialize(HttpRequest httpRequest) { }
            });

    Storage storage = storageBuilder.build();


    Storage.Objects.Get get = storage.objects().get(GAE_WEBDATA.PUBLIC_ZIP_BUCKET, mZipName);

    FileOutputStream stream = new FileOutputStream(file);
    try {
        get.executeAndDownloadTo(stream);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        stream.close();
    }
}

I get the following error:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
  "code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Login Required",
"reason" : "required"
 } ],
  "message" : "Login Required"
}

In cloud console I have Google Cloud Storage set to 'On'. The particular bucket permissions are set to 'All Users' = 'Reader'. What am I missing?

1

1 Answers

0
votes

When you try to read an object, bucket permissions aren't necessary. Instead, you need to set the OBJECT permissions to public-read.

You can fix the object permissions via the cloud console or from the command line via gsutil. The command is:

gsutil acl set public-read gs://bucketName/objectName