title: how to send and receive file by flask and axios
body: <p>In the node js, I send a post request, and hope to receive a file from the python flask server. What it sends is not relavent, and I just would like to receive the a jpeg file from the flask server:</p>
  <pre><code>const fs = require('fs');
  
  const axios = require('axios');
  
  const BASE_URL = &quot;http://localhost:5000&quot;;
  
  function send_test(test_name,...args) {
      const apiurl = `${BASE_URL}/send`;
      
      
      const form = new URLSearchParams();
      form.append('filename', test_name);
      const config = {
          headers: {
              'content-type': 'multipart/form-data'
          }
      };
      axios.request({
          url: apiurl,
          method: 'POST',
          headers:config,
          data: form,
      
      })
          .then(function (response) {
          
              
              console.log(response.data);
              fs.writeFileSync('result.jpeg', 
              response.data);
          
    })
    .catch(function (error) {
          console.log(error);
          
    });
  
  }
  result = send_test('test_name');
  </code></pre>
  <p>The flask server returns a jpeg, and it does not matter what it receives from the node js, it does not check the form and just sends a jpeg file:</p>
  <pre><code>from flask import Flask, request,send_file
  import os
  
  app = Flask(__name__)
  
  
  @app.route('/send', methods=['POST'])
  def send():
      print('send')
  
      extracted_name = 'test.jpeg'
     
          
      return send_file(extracted_name, mimetype=&quot;image/jpeg&quot;)
  </code></pre>
  <p>However, when I save file to 'result.jpeg', the file cannot be opened. I think the encoding of the file is important here. How to save the file by fs.writeFileSync()? The first a few bytes of response.data is like :</p>
  <p>����JFIFHH��xExifII*1&gt;i�FPicasa�0220��
  ���C</p>
  <p></p>