Flask保存一个空文件

时间:2019-03-29 07:49:14

标签: python flask

我的应用应该从用户那里接收数据,将其保存在本地,然后发送给Firebase存储。由于某种原因,即使在所需位置成功创建了文件,我也得到了一个没有内容的空文本文件。我究竟做错了什么?实际上,我正在遵循官方的Flask教程。

if 'file' in request.files:
            photo = request.files['file']
            result = td.process(photo)
            client = storage.Client()
            bucket = client.get_bucket("<my-app>.com")
            blob = bucket.blob("demo")
            filename = secure_filename(photo.filename)
            #photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            photo.save("./" + filename)
            #f = open(os.path.join(app.config['UPLOAD_FOLDER'], filename),"rb")
            #blob.upload_from_file(f)
            return jsonify(result)

1 个答案:

答案 0 :(得分:0)

photo.stream.seek(0)之前做photo.save("./" + filename)