3

I am trying to upload directly to Google Cloud Storage from a series of URLs. I have been trying to implement the solution form here: How to upload an image from web into Google Cloud Storage?

In particular, whenever I try to open a file using cloudstorage module,

options={'x-goog-acl': 'public-read', 'Cache-Control': 'private, max-age=0, no-transform'}
with gcs.open(filename, 'w', content_type=content_type, options=options) as f:
    f.write(image_bytes)

I get the following error:


AttributeError                            Traceback (most recent call last)
<ipython-input-8-dec1a5d39c62> in <module>()
     18 
     19 options={'x-goog-acl': 'public-read', 'Cache-Control': 'private, max-age=0, no-transform'}
---> 20 with gcs.open(filename, 'w', content_type=content_type, options=options) as f:
     21     f.write(image_bytes)
     22     f.close()

AttributeError: 'module' object has no attribute 'open'

I have already tried installing cloudstorage in an isolated environment but still had no luck.

Based on the reference below, cloudstorage.open() exist in https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/functions

Any idea where the problem could be?

Thanks!

Ivam
  • 379
  • 3
  • 12
Lilo
  • 59
  • 1
  • 6
  • Perhaps check a working example at [Write a CSV to store in Google Cloud Storage](https://stackoverflow.com/a/39525052/11154841). – questionto42 Jan 31 '22 at 21:23

1 Answers1

2

do print dir(gcs) to see what is in there. you may be installing a similarly named but different package.

It sounds like this is the one you want

https://github.com/GoogleCloudPlatform/appengine-gcs-client/tree/master/python/src/cloudstorage

and this is the function you are trying to use:

https://github.com/GoogleCloudPlatform/appengine-gcs-client/blob/master/python/src/cloudstorage/cloudstorage_api.py#L47

The readme.md for this repo points here:

https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/setting-up-cloud-storage

which says to do this:

pip install GoogleAppEngineCloudStorageClient -t <your_app_directory/lib>

Alex
  • 5,141
  • 12
  • 26