0

I recently moved my project from heroku to google cloud. It's written in flask and basically does some text summary (nothing fancy) of an uploaded .docx file. I was able to locally use files on heroku due to their ephemeral file system.

With google cloud, finding myself lost trying to use a file uploaded and running python functions on it.

The error I'm getting is: with open(self.file, 'rb') as file: FileNotFoundError: [Errno 2] No such file or directory: 'http://storage.googleapis.com/...'

Edited the specifics out for now but when I open the link in a browser it brings up the download window. I know the file gets there since I go to google cloud and everything is in the proper bucket.

Also is there a way to delete from the bucket immediately after python goes through the document? Currently have the lifecycle set to a day but just need the data temporarily runover.

I'm sorry if these are silly questions. Very new to this and trying to learn.

Thanks

Oh and here's the current code

gcs = storage.Client()
user_file = request.files['file']
local = secure_filename(user_file.filename)
blob = bucket.blob(local)
blob.upload_from_string(user_file.read(),content_type=user_file.content_type)
this_file = f"http://storage.googleapis.com/{CLOUD_STORAGE_BUCKET}/{local}"

then a function is supposed to open this_file

Adam
  • 11
  • 3

1 Answers1

1

returned a public_url to a file name to be processed and used

   def open_file(self):
    url = self.file
    file = BytesIO(requests.get(url).content)
    return docx.Document(file)
Adam
  • 11
  • 3
  • also made use of the /tmp/ folder for easier use. Let's you use standard python methods. – Adam May 30 '20 at 18:42