简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM