Unable to upload files with Flask on Heroku Unable to upload files with Flask on Heroku flask flask

Unable to upload files with Flask on Heroku


Heroku is interrupting the request to store data at uploads/ because they prefer you use temporary storage at tmp/

Any tmp/ files will not be there when the dyno restarts because Heroku filesystems are ephemeral.

Following the 12-factor app principles, Heroku expects that if your app needs storage you'll use a storage service -- the popular solution is AWS S3 also available as an add-on.


This is incorrect, Heroku does not actually interrupt requests at /uploads. You are hitting the issue described here.

The other answer is correct that any files not checked into git will be gone after a dyno cycle or rebuild, and that 12 factor principles should be followed, and if you need to keep the files for any length of time after upload, they should be sent to S3.

However, the H18 error code most often means that the socket successfully connected, some data was sent as part of a response by the app, but then the socket was destroyed without completing the response.

There aren't any tracebacks in your logs, so (from the linked help article above):

you'll need to look more closely at the handlers for the specific request that's failing. Logging each step of the response, including the x-request-id header, can help.

Here are the docs on request routing on Heroku: https://devcenter.heroku.com/articles/http-routing