title: save csv file in postgres database using flask
body: <p>i want to save my csv file in database using flask. in frontend i wrote a function to send the csv file to backend. here is the code:</p>
  
  <pre><code>    saveCsvFile = () =&gt; { 
           console.log('saveCsvFile ...', this.state.csvFile);
           axios.post( this.state.apiUrl+'/api/v1/SalesLead/saveCsv', {
              'csv_file':this.state.csvFile,
                  },  {}  )
  
                 };
  
    &lt;form&gt;
     &lt;input onChange={this.fileHandler} type="file" accept=".csv,text/csv" /&gt;
     &lt;button onClick={() =&gt; this.saveCsvFile()} type="submit" form="form1" value="Submit"&gt;Submit&lt;/button&gt;
     &lt;/form&gt;
  </code></pre>
  
  <p>And i wrote a simple function to read the csv file in python(flask). here is the code:</p>
  
  <pre><code>@SalesLeadController.route('/saveCsv', methods=['POST'])
  
  def upload_csv():
  
      print('upload_csv')
  
      if request.method == 'POST':
  
          csv_file = request.files['file']
  
          csv_reader = csv.reader(csv_file, delimiter=',')
  
          for row in csv_reader:
  
              user = SalesLead(username=row[0], email=row[1])
  
              db.session.add(user)
  
              db.session.commit()
  
          return Response(json.dumps({'status': 'success', 'message': 'data successfully saved.'}), status=200, mimetype='application/json')
  </code></pre>
  
  <p>But i am getting this error after uploading the CSV file:</p>
  
  <pre><code>400 Bad Request: KeyError: 'file'
  </code></pre>
  
  <p>How can i solve this error?</p>