html - 如果我在本地开发或开发云服务器上上传文件数据的差异[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 上写入错误的文件,然后无法下载和观看。
有谁知道发生了什么?我快疯了
解决方案
推荐阅读
- c# - 在 Umbraco CMS 项目中动态添加文本到视图
- c# - 为什么我的 Windows 服务没有因致命错误而停止?
- javascript - jQuery - 翻转 DIV 问题
- javascript - 无法理解 Promise 并捕捉行为
- c++ - VS 2017 项目中的恒定 LNK1104 错误
- r - r 传单:如何获得标记被拖到的纬度/经度?
- ibm-appid - 我们如何使用 IBM Appid 对 Kibana 用户进行身份验证?
- c++ - 如何从表中选择特定值
- typescript - Angular 6 反应形式获得键名
- ruby-on-rails - 如何拥有与显示名称具有不同参数值的字段