I have been trying to create a csv file from a string in Cloud Functions. It is storing the file temporarily in /tmp folder. Then the file goes to the bucket.
Following is my code -
def upload_blob(bucket_name, source_file_name, destination_blob_name):
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_file(source_file_name)
message = "Data for CSV file"
csv = open('test.csv', "w") #ERROR HERE
csv.write(message)
with open('/tmp/test.csv', 'r') as file_obj:
upload_blob('test-bucket', file_obj, 'test.csv')
I am getting the following error -
File "/user_code/main.py", line 30, in hello_main csv = open('test.csv',
"w") OSError: [Errno 30] Read-only file system: 'test.csv'
How to make this file writable?