Heroku应用程序的免费层是否支持文件上传? [英] Does the free tier of Heroku apps support file upload?

查看:71
本文介绍了Heroku应用程序的免费层是否支持文件上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试MEAN堆栈应用程序.我有一个Node.js后端,可以处理文件上传(通过 fs/multer ).但是,在生产环境中尝试击中它时,我收到503错误.

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.

在本地,一切正常.我正在使用Heroku的免费套餐;该层是否被锁定为不允许文件上传?

Locally everything is working fine. I am using Heroku's free tier; is that tier locked to not allow file upload?

我当前正在尝试(已经尝试了几次)的上传文件只有36kb( .png ).

The upload I'm trying currently (have tried several) is only 36kb (.png).

浏览了我的日志,找到了503-

Went through my logs and found the 503-

<代码>2018-10-26T20:39:24.352297 + 00:00 heroku [router]:at =错误代码= H13 desc =连接已关闭且无响应" 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 = http2018-10-26T20:39:24.306975 + 00:00 app [web.1]:(node:20)[DEP0013] DeprecationWarning:不推荐使用不带回调的异步函数.2018-10-26T20:39:24.307037 + 00:00 app [web.1]:(node:20)[DEP0013] DeprecationWarning:不调用没有回调的异步函数是不推荐的.2018-10-26T20:39:24.318818 + 00:00 app [web.1]:fs.js:1132018-10-26T20:39:24.318822 + 00:00 app [web.1]:抛出错误;//忘记了回调但不知道在哪里?使用NODE_DEBUG = fs2018-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]:错误:ENOENT:没有这样的文件或目录,mkdir'./uploads/18'

推荐答案

文件上传不应自行生成HTTP 503.您应该检查日志(通过 heroku日志)以获取有关失败原因的更多信息.话虽如此,即使您解决了这个问题,您可能也需要对处理文件上传的方式进行根本性的改变.

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.

所有Heroku层都有一个临时文件系统.每当您的dyno重新启动时,对文件系统所做的任何更改都会丢失,这经常发生(每天至少一次).

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).

官方推荐是将上传的文件放入第三方服务(如Amazon S3). multer-s3 库应该可以提供帮助那个.

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.

这篇关于Heroku应用程序的免费层是否支持文件上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆