Frank B.
Frank B.

Reputation: 204

How do I access a text file from GCP Storage and parse it?

I have an app I want to make for Android. I have decided to store the information I will display in a text file and parse it, rather than a database since the data is so simple.

The info is just two lines of text, a word and a short description of that word. I want the app to get each pair (word, description) from the text file and display it on a card in the app.

I stored the .txt file in Google Cloud Platform Storage and now I need help writing the code to access the file(s) and parse them to use in a Cards UI.

I can find no helpful examples of how to get this file then parse it in the app in a smooth way.

Upvotes: 1

Views: 987

Answers (1)

Lak
Lak

Reputation: 4166

You can use a client library to open the file and read it. For example, the Python client library is at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/functions

and your code would look like this:

import cloudstorage

try:
  gcs_file = cloudstorage.open(filename, 'r', content_type='text/plain')
  # process as normal ...
except cloudstorage.NotFoundError:
  pass

Sample Java client code is at https://cloud.google.com/storage/docs/xml-api-java-samples

Upvotes: 0

Related Questions