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

2024-04-19 22:55:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个关于离子的项目。我有一个服务器安装在烧瓶,我想发送图像,并处理他们与这个。你知道吗

我目前正在做以下工作:

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))

在烧瓶里,我把它当作“数据”而不是“文件”。你知道怎么修吗?你知道吗


Tags: jsonapphttpimgdata烧瓶applicationerror