1
votes

I am writing files into Google storage from appengine using REST api.

My code looks like this:

        url = 'http://storage.googleapis.com/' + bucketName + filePath

    LOG.debug('Attempting to write file: ' + url)

    '''
    compute expiry time one year in the future
    '''
    expiresDate = datetime.utcnow() + timedelta(days=zconfig.CACHE_EXPDAY)
    formatStr = '%a, %d %b %Y %H:%M:%S GMT'

    start_cloud = time.time()

    headers = {'Content-Type' : mime,
               'Content-Length' : len(imageBytes),
               'Cache-Control' : 'Expires=' + expiresDate.strftime(formatStr),
               'x-goog-api-version' : '2',
               'x-goog-acl' : 'public-read'}

    resp, content = http.request(url, 'PUT', body=imageBytes, headers=headers)

As per the google storage api docs, the REST api takes a 'x-goog-acl' header that can change the ACl on the object.

However, after this object is created, the ACL is still not set to public-read. I can see that both from gsutil, as well as from the GS browser.

Can someone tell me what I am doing wrong?

EDIT: jterrace pointed out that I am not passing the headers into the request. I fixed that. But it still does not set the public-read ACL on the object.

2
Did you forget to pass the headers dictionary to the request function? - jterrace

2 Answers

1
votes

It looks like you're not actually passing the headers dictionary to the request function:

resp, content = http.request(url, 'PUT', body=imageBytes)

should be:

resp, content = http.request(url, 'PUT', body=imageBytes, headers=headers)
0
votes

Although I don't know exactly why/how, but I think you are not logged in as the project owner when you visit the old and new console. The old console will not display the "share publicly" option (and will not allow you to toggle it) if you don't have permission to get/set object ACL. The new console is better in the sense that it actually tells you that.

Can you double check that the user you logged in as is the owner of the project?