Cloud Function will triggered once a file gets uploaded in the storage, My File Name : PubSubMessage. Inside Text : Hi, this this the first message
from google.cloud import storage
storage_client = storage.Client()
def hello_gcs(event, context):
file = event
bucket = storage_client.get_bucket(file['bucket'])
blob = bucket.blob(file['name'])
contents = blob.download_as_string()
print('contents: {}'.format(contents))
decodedstring = contents.decode(encoding="utf-8", errors="ignore")
print('decodedstring: \n{}'.format(decodedstring))
print('decodedstring: \n{}'.format(decodedstring))
------WebKitFormBoundaryAWAKqDaYZB3fJBhx
Content-Disposition: form-data; name="file"; filename="PubSubMessage.txt"
Content-Type: text/plain
Hi, this this the first line.
Hi ,this is the second line.
hi this is the space after.
------WebKitFormBoundaryAWAKqDaYZB3fJBhx--
My Requirements.txt file
google-cloud-storage
requests==2.20.0
requests-toolbelt==0.9.1
How do i get the actual string inside the file "Hi, I am the first message....." ?
What is the best possible way to get the text from a file? TIA