Can not upload files to local disk

my web app upload files and save them to local storage (in a folder called “data” in root directory) successfully. But it doesn’t seem to work on Render live version. I get the following error. Any help would be appreciated. thanks

Jul 12 11:15:58 PM  Traceback (most recent call last):
Jul 12 11:15:58 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
Jul 12 11:15:58 PM      response = self.full_dispatch_request()
Jul 12 11:15:58 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
Jul 12 11:15:58 PM      rv = self.handle_user_exception(e)
Jul 12 11:15:58 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
Jul 12 11:15:58 PM      rv = self.dispatch_request()
Jul 12 11:15:58 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
Jul 12 11:15:58 PM      return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
Jul 12 11:15:58 PM    File "/opt/render/project/src/app.py", line 86, in index
Jul 12 11:15:58 PM      file.save(file_path)
Jul 12 11:15:58 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/werkzeug/datastructures.py", line 3002, in save
Jul 12 11:15:58 PM      dst = open(dst, "wb")
Jul 12 11:15:58 PM  FileNotFoundError: [Errno 2] No such file or directory: 'uploads/emails.txt'
Jul 12 11:15:58 PM  ERROR:app:Exception on / [POST]
Jul 12 11:15:58 PM  Traceback (most recent call last):
Jul 12 11:15:58 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
Jul 12 11:15:58 PM      response = self.full_dispatch_request()
Jul 12 11:15:58 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
Jul 12 11:15:58 PM      rv = self.handle_user_exception(e)
Jul 12 11:15:58 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
Jul 12 11:15:58 PM      rv = self.dispatch_request()
Jul 12 11:15:58 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
Jul 12 11:15:58 PM      return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
Jul 12 11:15:58 PM    File "/opt/render/project/src/app.py", line 86, in index
Jul 12 11:15:58 PM      file.save(file_path)
Jul 12 11:15:58 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/werkzeug/datastructures.py", line 3002, in save
Jul 12 11:15:58 PM      dst = open(dst, "wb")
Jul 12 11:15:58 PM  FileNotFoundError: [Errno 2] No such file or directory: 'uploads/emails.txt'```

Hi,

You mentioned a “data” folder, but the error seems to be referencing something different:

No such file or directory: 'uploads/emails.txt'

Render instances have an ephemeral filesystem, meaning any file written to the instance after it has booted will be lost when it next restarts (e.g. spun down if on free instance type, next deploy, manual restart etc.).

If you want to use file uploads on your service, you’ll need to have a persistent store, e.g. a Render Disk or an external service like AWS S3.

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.