问题
I am testing out a MEAN stack application. I have a Node.js backend which handles file upload (via fs/multer
). However I'm receiving a 503 error when trying to hit it in production.
Locally everything is working fine. I am using Heroku's free tier; is that tier locked to not allow file upload?
The upload I'm trying currently (have tried several) is only 36kb (.png
).
Went through my logs and found the 503-
2018-10-26T20:39:24.352297+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/media/upload" host=www.example.co.uk request_id=5388711c-bc99-4e42-9dbd-7b645fbefb43 fwd="90.222.69.255" dyno=web.1 connect=1ms service=130ms status=503 bytes=0 protocol=http
2018-10-26T20:39:24.306975+00:00 app[web.1]: (node:20) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.
2018-10-26T20:39:24.307037+00:00 app[web.1]: (node:20) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.
2018-10-26T20:39:24.318818+00:00 app[web.1]: fs.js:113
2018-10-26T20:39:24.318822+00:00 app[web.1]: throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
2018-10-26T20:39:24.318824+00:00 app[web.1]: ^
2018-10-26T20:39:24.318826+00:00 app[web.1]:
2018-10-26T20:39:24.318828+00:00 app[web.1]: Error: ENOENT: no such file or directory, mkdir './uploads/18'
回答1:
File uploads shouldn't generate HTTP 503 on their own. You should check your logs (via heroku logs
) to get more information about what's failing. Having said that, even if you resolve this issue you'll probably need to make a fundamental change with the way you're handling file uploads.
All Heroku tiers have an ephemeral filesystem. Any changes made to the filesystem are lost whenever your dyno restarts, which happens frequently (at least once per day).
The official recommendation is to put uploaded files onto a third-party service like Amazon S3. The multer-s3 library should be able to help with that.
来源:https://stackoverflow.com/questions/53016153/does-the-free-tier-of-heroku-apps-support-file-upload