<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Michael,</div><div><br></div><div>Is it possible that the uploaded file size is causing the server to run out of memory when saving? You can try saving it in chunks:<br></div><div><br></div><span style="font-family:monospace,monospace">def read_in_chunks(file_object, block_size=1024):<br>    """Return a generator which yields data in chunks.<br><br>    Source: `read-file-in-chunks-ram-usage-read-strings-from-binary-file<br>    <<a href="http://stackoverflow.com/questions/17056382/">http://stackoverflow.com/questions/17056382/</a><br>    read-file-in-chunks-ram-usage-read-strings-from-binary-files>`_<br><br>    :param file_object: File object to read in chunks.<br>    :type file_object: file object<br><br>    :param block_size: (optional) Chunk size.<br>    :type block_size: int<br><br>    :yield: The next chunk in file object.<br>    :yield type: `bytes`<br>    """<br>    for chunk in iter(lambda: file_object.read(block_size), b''):<br>        yield chunk</span><br></div><div dir="ltr"><div><br></div><div><span style="font-family:monospace,monospace">@app.route("/add", methods=["GET", "POST"])<br>def add():</span></div><span style="font-family:monospace,monospace">    ...</span></div><span style="font-family:monospace,monospace">    # gpx_file.save(gpx_fspath)</span></div><div dir="ltr"><span style="font-family:monospace,monospace">    with open(gpx_fspath, 'wb') as file_:<br>        for data in read_in_chunks(gpx_file.stream):<br>            file_.write(data)</span><br></div><div dir="ltr"><div dir="ltr"><div><br></div><div><a href="https://github.com/scottwernervt/flask-upload-issue-arm/blob/master/views.py">https://github.com/scottwernervt/flask-upload-issue-arm/blob/master/views.py</a></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 3, 2018 at 9:42 AM Michael Bayer <<a href="mailto:lists@mjbayer.de">lists@mjbayer.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <div class="m_-4878034279664203744moz-text-flowed" style="font-family:-moz-fixed;font-size:12px" lang="x-unicode">
      <br>
      Am 02.10.2018 um 23:39 schrieb Geert Stappers:
      <br>
      <blockquote type="cite" style="color:#000000">On Tue, Oct 02,
        2018 at 05:05:47PM +0200, Michael Bayer wrote:
        <br>
        <blockquote type="cite" style="color:#000000">Hi everyone,
          <br>
          <br>
          I discovered a funny behavior of my flask app, when running on
          ARM
          <br>
          based apache wsgi servers. Could you please give me some hints
          to
          <br>
          debug this? <span class="m_-4878034279664203744moz-smiley-s1" title=":-)"></span>
          <br>
          <br>
          I have a flask application, that supports file upload.
          <br>
          It runs on an ARM based debian stable server with apache wsgi.
          <br>
          If I upload small files, everything is fine. The problem
          appears,
          <br>
          when I upload files with a file size >64kb. The famous "Bad
          request
          <br>
          - The browser (or proxy) sent a request that this server could
          not
          <br>
          understand." pops up.
          <br>
          <br>
          Things I tried out so far:
          <br>
          - Deploying my flask app to my productive ARM based webserver
          (debian
          <br>
             stable): Here I discovered the issue.
          <br>
          - Running in flask's development wsgi server on my Development
          PC:
          <br>
              No problem, I can upload files with any size I want.
          <br>
          - Clean debian stable installation in a virtualbox on my
          Development
          <br>
             PC (AMD64) same packages as my productive server, but AMD64
          instead
          <br>
             of armhf (apache, mod_wsgi): Again no problems at all.
          <br>
          - Clean installation of raspian on a spare ARM Raspberry Pi
          (based on
          <br>
             debian 9) with apache, mod_wsgi: Here comes the problem
          again!
          <br>
          - Increase apache LogLevel to debug -> no error logged
          <br>
          - Activate FileLogging inside my flask app -> no error
          logged
          <br>
          <br>
          Have you seen anything like this?
          <br>
        </blockquote>
        No.
        <br>
        <br>
        Thing that intriges me, is that 64K   is a 16-bit limit.
        <br>
        ARMHF versus AMD64  is 32-bit vs 64-bit ...
        <br>
      </blockquote>
      Thanks for your answer!
      <br>
      Yes, this is strange. I also don't have an explanation
      <br>
      <blockquote type="cite" style="color:#000000">
        <br>
        <blockquote type="cite" style="color:#000000">I unfortunately
          do not have much experience with web servers/development
          <br>
          so I'm stuck with my debugging approaches :/
          <br>
          <br>
          What could I do besides that?
          <br>
        </blockquote>
        Consider it a none flask problem, it will allow you to look at
        Apache,
        <br>
        uWSGI, Python and other links in the chain. Is a webproxy
        involved??
        <br>
      </blockquote>
      <br>
      There is no proxy in the network.
      <br>
      <br>
      <br>
      <blockquote type="cite" style="color:#000000">
        <blockquote type="cite" style="color:#000000">What information
          do you need from my side?
          <br>
          I can provide any code/configuration you need.
          <br>
        </blockquote>
        That will help reproducing the problem.
        <br>
      </blockquote>
      I created a minimal example to reproduce the error:
      <br>
      <a class="m_-4878034279664203744moz-txt-link-freetext" href="https://github.com/mjbayer/flask-upload-issue-arm" target="_blank">https://github.com/mjbayer/flask-upload-issue-arm</a>
      <br>
      <br>
      This repo contains code, configuration and example files that can
      be used for upload.
      <br>
      <br>
      Here is a demo Raspberry Pi (just for that purpose) to try it out:
      <br>
      <a class="m_-4878034279664203744moz-txt-link-freetext" href="http://rgb.mjbayer.de/trackdb/" target="_blank">http://rgb.mjbayer.de/trackdb/</a>
      <br>
      (I could also give ssh access to the Raspi if required)
      <br>
      <br>
      If you run the code in flasks development wsgi server or apache
      mod_wsgi on AMD64, you will not see the issue.
      <br>
      <br>
      <br>
      Michael
      <br>
      <br>
    </div>
  </div>

_______________________________________________<br>
Flask mailing list<br>
<a href="mailto:Flask@python.org" target="_blank">Flask@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/flask</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Scott Werner<br><a href="mailto:scott.werner.vt@gmail.com" target="_blank">scott.werner.vt@gmail.com</a><br></div></div></div></div>