【问题标题】:Python flask heroku - Image Upload Field (WTForms) makes APP timeout (takes too long)Python flask heroku - 图像上传字段(WTForms)使APP超时(花费太长时间)
【发布时间】:2017-02-02 08:20:56
【问题描述】:

我目前在 heroku 上部署了一个应用程序。

它从 1 天开始运行,我在日志中注意到用户在某个站点上经常收到 H13 或 H28 错误。

我已经发现了问题。在这个网站上,用户可以上传图片(最多 10 张)。 我在允许多选的图像中使用 1 个输入字段,因此上传多张图像的唯一方法是一次上传。

WTForms:

bild = FileField("Weitere Bilder hochladen", validators=[FileAllowed(['jpg', 'png', 'jpeg'], 'Nur Bilder im Formal JPG oder PNG')])

如果请求未被处理,Heroku 的默认超时时间为 30 秒。但是上传多张图片的过程太长,因此heroku中断了这个过程并显示了自定义错误页面。

我的想法:

为了解决这个问题,我会禁用多选并在 WTForms 中添加 9 个附加 FileField,因此用户必须一张一张上传图像,这是要走的路吗?

或者我应该添加一个进度条并增加超时,这里的最佳做法是什么?

编辑

好的,我找到了一些解决方案,但我想使用进度条并增加 heroku 的请求超时时间。

我会尝试上传一个新的procfile:

web: gunicorn main:app --timeout 120

【问题讨论】:

    标签: python heroku filefield


    【解决方案1】:

    好的,我设法解决了这个问题,但我做得很快而且效率不高。

    最好的解决方案似乎在这里: Heroku`s solution

    我通过增加应用程序的超时时间解决了这个问题。因此我将新的 procfile 上传到我的 heroku 应用程序:

    web: gunicorn main:app --timeout 120
    

    之后,我在表单的提交按钮上实现了加载动画,该按钮发出了长请求。我添加的部分在span tag:

    <button type="submit" class="btn add-btn"> <span class="ani-holder"><span class="glyphicon glyphicon-refresh glyphicon-refresh-animate"></span></span> Zimmer einstellen </button>
    

    最初我将动画设为display: none;。如果单击按钮,则表单将提交。这里我使用 jQuery 将加载动画的显示更改为 display: inherit; 并使其看起来更好我还更改了按钮的背景颜色:

    $('#regi').submit(function(){
        $('.ani-holder').css("display", "inherit");
        $('.add-room-container .add-btn').css("background-color", "#afddfe");           
    });
    

    该函数在表单提交请求时执行。之后我redirect url 并重新加载页面,就这样。如果请求很快,那么您将看不到任何内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-14
      • 2011-11-18
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多