从vue获取文件输入并推送到Python代码

2024-06-16 11:37:03 发布

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

我有一个Vue项目和一个python脚本。我想使用Vue输入一个文件,并在python scrpit中使用上传的文件。 现在我有两个完全不同的Vue项目和python文件没有集成在一起。 我该怎么做? 有什么建议吗


Tags: 文件项目脚本建议vuescrpit
1条回答
网友
1楼 · 发布于 2024-06-16 11:37:03

我可以提供API Rest机制作为一个选项。 例如,请参见以下代码:

<form id="form" 
      enctype="multipart/form-data" 
      @change="onUploadFile">
    <input type="file" id="file" name="file">
</form>

onUploadFile: function (event) {
    const file = event.target.files[0]
    axios.post('upload_file', file, {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
    })
    .then(console.log)
    .catch(console.error);
}

在Python中,您应该得到这个POST方法

相关问题 更多 >