一旦文件上传到存储中,就会触发云功能,我的文件名:PubSubMessage。内文:嗨,这是第一条消息
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--
我的Requirements.txt 文件
google-cloud-storage
requests==2.20.0
requests-toolbelt==0.9.1
我如何获得文件“嗨,我是第一条消息.....”中的实际字符串?
从文件中获取文本的最佳方法是什么?TIA