<script>import axios from'axios'exportdefault{data(){return{};},
methods:{uploadSectionFile(param){let fileObj = param.file
let form =newFormData()
form.append("fileToUpload", fileObj)
console.log(form)// output is: FormData {}; 需要使用 .get() 来读取
console.log(form.get("fileToUpload"))// output is exactly the fileObj
axios.post("http://127.0.0.1:5000/uploadFile", form,{
headers:{'content-type':'multipart/form-data'}})},}}</script>
Flask
from flask import request
api = Blueprint('api', __name__)@api.route('/uploadFile', methods=['POST'])defuploadFile():
file0 = request.form.get('fileToUpload')# request.form outputs ImmutableMultiDict([]); request.form.get('fileToUpload') outputs Nonefile= request.files.getlist('fileToUpload')[0]# the type of file is FileStorage
upload_dataset = pd.read_csv(file)# deal with upload_dataset ....return