0

I have csv objects that i can download with a blobkey. The endpoint looks like this /data?key=[blobkey]. If i were to go into the datastore and find the csv key, replace it with the blobkey, i get the csv downloaded. The problem occurs when trying to generate new csv files. The bucket that i am saving the new scv files is one i created just recently. What should happen is that i should be getting a blobkey that i can replace in the endpoint and get a csv object. But i do not get anything.

My thinking is that i am just saving it inside of the wrong bucket. I should try to save it into the original bucket, where the other csv objects are. But i do not know how to search for those objects. I do know for sure that the csv exits because i can navigate to the bucket and download it there from the url https://storage.cloud.google.com/.../my.csv

My question is, how do i find the position of the bucket where the previous csv's were saved?

How i am downloading CSV in development server:

# obtain a blobkey
blob_key = BlobKey(blobstore.create_gs_key(u'/gs' + gcs_filename))

# pass the blobkey to the endpoint
/data?key=blob_key

the bucket i am is

/user-exports/user_key/timestamp/mydata.csv
VickTree
  • 889
  • 11
  • 26
  • Could you please elaborate on how are you downloading the csv file? IF you have [access to the URL](https://cloud.google.com/storage/docs/downloading-objects#rest-download-object), then you can get the bucket name from that. – Joss Baron Feb 18 '20 at 19:59
  • I added more information on how it is begin downloaded on it. Is it safe to serve a download using `https://storage.googleapis.com/storage/v1/b/[BUCKET_NAME]/o/[OBJECT_NAME]?alt=media`. Also, could you please link some python code that makes use of it, i am having a hard time understanding how to turn it into a download it – VickTree Feb 18 '20 at 20:07
  • Any example of downloading objects in Cloud Storage programaticaly will use client libraries. In the case of Python, the examples uses the [Cloud Storage API](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/storage/cloud-client/quickstart.py). The way in which you can [download the objects](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/storage/cloud-client/storage_download_file.py) are different: ` bucket = storage_client.bucket(bucket_name) blob = bucket.blob(source_blob_name) blob.download_to_filename(destination_file_name)` – Joss Baron Feb 18 '20 at 20:26
  • thanks! why does it require a `destination_file_name`? this is the path of it in the bucket? I do not want to save anything, it is already saved. I just need to retrive it. When i fill out the with the `bucket`, `filename` and `destination_file_name`, it gives me `a IOError: [Errno 30] Read-only file system: ` Could you please clarify what you mean with the different ways to download? – VickTree Feb 18 '20 at 21:01
  • i am having a hard time figuring out what `destination_file_name` should be. If the `destination_file_name` is a local directory, what can i enter it as so it gets downloaded to the download folder of users computers? – VickTree Feb 18 '20 at 21:38
  • Hi, to read the content of the file without downloading something like this should work (this is in java): `Blob blob = storage.get(BUCKET_URL, OBJECT_URL); String fileContent = new String(blob.getContent()); System.out.println(fileContent)`, take a look into [this question](https://stackoverflow.com/questions/59842055/how-to-read-the-content-of-file-in-gcs-bucket/59849977#59849977). Is this what you are interested in? – Joss Baron Feb 18 '20 at 22:59
  • i would like to download it, but i keep getting this error because i do not know what to set `destination_file_name` as. `File "/base/data/home/apps/s~proj-noah/32.424681822435028819/lib/google/cloud/storage/blob.py", line 777, in download_to_filename with open(filename, "wb") as file_obj: IOError: [Errno 30] Read-only file system: 'My-Spottings.csv' ` – VickTree Feb 19 '20 at 16:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/208140/discussion-between-braulio-baron-and-vicktree). – Joss Baron Feb 19 '20 at 16:59

0 Answers0