I am trying to create a Google Function with Python that will accept variables and upload a file to a stoage bucket. Here is the code to upload, below it is the error I'm getting. I have double checked the path and filename that I am sending via the function URL, but it's not working. The URL is similar to this: https://us-central1-gcpdemo.cloudfunctions.net/uploaddemo?pathtofile=c:\Temp\&blobname=IMG_3014.PNG&bucketname=gcpingestionbucketdemo
from google.cloud import storage
def hello_world(request):
"""Responds to any HTTP request.
Args:
request (flask.Request): HTTP request object.
Returns:
The response text or any set of values that can be turned into a
Response object using
`make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
"""
#add this lines at top
path_to_file = request.args.get('pathtofile')
blob_name = request.args.get('blobname')
#gcpingestionbucketdemo
bucket_name = request.args.get('bucketname')
#define client
# use service account credentials .
# storage_client = storage.Client.from_service_account_json('creds.json')
storage_client = storage.Client()
#define bucket
bucket = storage_client.get_bucket(bucket_name)
#Blob: File name that will be saved.
blob = bucket.blob(blob_name)
blob.upload_from_filename(path_to_file)
textPayload: "Traceback (most recent call last): File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 402, in run_http_function result = _function_handler.invoke_user_function(flask.request) File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 268, in invoke_user_function return call_user_function(request_or_event) File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 261, in call_user_function return self._user_function(request_or_event) File "/user_code/main.py", line 30, in hello_world blob.upload_from_filename(path_to_file) File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 2458, in upload_from_filename with open(filename, "rb") as file_obj: FileNotFoundError: [Errno 2] No such file or directory: 'c:\Temp\'