在Ionic和Flask中发送和保存图像时出错

时间:2018-09-02 15:45:52

标签: python angularjs flask ionic3

我正在开发有关Ionic的项目。我在Flask上安装了一台服务器,我想发送图像并对此进行处理。

我目前正在执行以下操作:

this.uploadFile (this.canvas.nativeElement.toDataURL ("image / jpeg")); 

uploadFile(img) {
    let postParams = { file: img };

    this.http.setDataSerializer("json");
    this.http.post('http://46.101.150.118:5000/upload', postParams,
        {
            "Accept": "application/json",
            "Content-Type": "application/json"
        }
    ).then(data => {
        this.drawCanvas(data);
    }).catch(error => {
        console.log(error);
    });
}

瓶号:

@app.route('/upload', methods=['POST'])
def upload():
    file = request.files['file']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

在烧瓶中,我将其作为“数据”而不是“文件”接收。知道如何解决吗?

0 个答案:

没有答案