Recommand · November 22, 2021 0

Can't get file from POST request using Flask and Bootstrap-Vue Form File Input

I’m trying to upload and image using Bootstrap-Vue Form File Input and send it to Flask Backend via POST using Axios library, then store in a folder.

My problem is that Flask can’t find "file" in "request.files". Pretty sure I’m falling in a rookie mistake.

That’s my code:


  <div class="mx-5 container-fluid">
    <div class="mx-5 row">
      <div class="col-sm-10">
                  placeholder="Choose a file or drop it here..."
                  drop-placeholder="Drop file here..."

import axios from 'axios';

export default {
  data() {
    return {
      file: null,
  methods: {
    submitFile() {
      /* Initialize the form data */
      const path = 'http://localhost:5000/single-file';
      const formData = new FormData();
      /* Add the form data we need to submit */
      formData.append('file', this.file);
      /* Make the request to the POST /single-file URL */,
          headers: {
            'Content-Type': 'multipart/form-data',
        }).then(() => {
        // console.log('SUCCESS!!');
        .catch(() => {
          // console.log('FAILURE!!');


from flask import Flask, jsonify, request, send_file, redirect, url_for
from werkzeug.utils import secure_filename
import os

# configuration
DEBUG = True
UPLOAD_FOLDER = '/images'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}

@app.route('/single-file', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            print('No file part')
            return redirect(request.url)
        file = request.files['file']
        # If the user does not select a file, the browser submits an
        # empty file without a filename.
        if file.filename == '':
            print('No selected file')
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
  ['UPLOAD_FOLDER'], filename))
            return redirect(url_for('download_file', name=filename))
    return ''

if __name__ == '__main__':

I get HTTP code 302 (redirect) and print in console ‘No file part’.

Any help would be very apreciated.