首页 > 解决方案 > 如果我在本地开发或开发云服务器上上传文件数据的差异[Flask-lambda]

问题描述

我在这个问题上失去了理智:

我有一个 html 文件上传器,它返回一个烧瓶应用程序读取的文件。然后将该文件保存在 S3 存储桶中。

html是这样的:

<form class="box" action="{{ to_url }}" method="POST" id="submit-form" enctype="multipart/form-data">
     <div class="file is-boxed">
        <label class="file-label">
          <input class="file-input" type="file" name="file">
          <span class="file-cta">
            <span class="file-icon">
              <i class="fas fa-upload"></i>
            </span>
            <span class="file-label">
              Carica file
            </span>
          </span>
        </label>
      </div>
</form>

烧瓶代码是这样的:

@app.route('/upload_participant_data', methods=['POST']) #definisce etodo ed endppoint
def upload_participant_data():
    ....
    ff = request.files['file']
    ....
    ff.seek(0)
    print (ff.read(30))

无论如何,如果我运行代码并在本地打印文件的前 30 位,它会返回这些值,这些值是正确的:

b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C\x00\t\x06\x07\x08 \x07'

另一方面,如果我将我的烧瓶应用程序部署在 lambda 应用程序上,则应用程序中的所有内容都按预期工作,除了现在文件的前 30 位被读取为:

b'\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00 \xef\xbf'

当然,文件的其余部分也会发生同样的情况(完全不同)。这在级联上会导致在 s3 上写入错误的文件,然后无法下载和观看。

有谁知道发生了什么?我快疯了

标签: htmlflaskamazon-s3aws-lambdaserverless

解决方案


推荐阅读