I'm new to Python and Google Cloud. Using Flask I have created a web page where a user can choose a file from their computer and upload it to a GCS bucket that I have already created. I'm following Google's documentation example which uses the Google Python API library. I'm able to upload files whose names are just a single word, like 'image' but if my file is named 'image one' then I get the following error- FileNotFoundError: [Errno 2] No such file or directory: 'image one.jpg'
Here's my code:
@app.route('/upload', methods = ['GET' , 'POST'])
def upload():
if request.method == "POST":
f = request.files['file']
f.save(secure_filename(f.filename))
gcs_upload(f.filename)
def gcs_upload(filename):
storage_client = storage.Client() # instantiate a client
bucket = storage_client.bucket('bucket_name')
blob=bucket.blob(filename) # file name at the destination should be the same
blob.upload_from_filename(filename) # file to be uploaded
if __name__ == '__main__':
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
app.run(port=8080, debug=True)
If I'm writing a production level application then I would want a user to upload a file even if it has spaces in its name.