Unable to upload files with Flask on Heroku

前端 未结 2 2013
暗喜
暗喜 2020-12-19 10:32

I\'m attempting to add a file addition button that uploads a file to a folder on my Flask Heroku app but I get an application error when I hit the submit button.

<         


        
相关标签:
2条回答
  • 2020-12-19 11:05

    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

    0 讨论(0)
  • 2020-12-19 11:10

    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.

    0 讨论(0)
提交回复
热议问题