title: RESTful API with python and flask to request and read a text file
body: <p>I am trying to read a text file using flask framework. This is my code</p>
  
  <pre><code>import os
  from flask import Flask, request, redirect, url_for, flash,jsonify
  from werkzeug.utils import secure_filename
  
  
  app = Flask(__name__)
  
  
  @app.route('/index', methods=['GET'])
  def index():
      return 'Welcome'
  
  @app.route('/getfile', methods=['POST'])
  def getfile():
      file = request.files['file']
      with open(file,'r') as f:
          file_content = f.read()
      return jsonify(file_content)    
  
  if __name__ == '__main__':
      app.run(host = '0.0.0.0')
  </code></pre>
  
  <p>I am using POSTMAN to check it, <a href="https://i.stack.imgur.com/3wS5p.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3wS5p.jpg" alt="pic"></a></p>
  
  <p>unfortunately it sends bad requests 400. I requested file as <code>request.file</code>.
  The .txt is residing in my disk at C:/Users/rbby/Desktop/Programs/hello.txt</p>
  
  <p>The GET method is working fine. POST is not working for me. Is there anything else i should add from my above code? </p>
  
  <p>I referred to this link <a href="https://stackoverflow.com/questions/39801728/using-flask-to-load-a-txt-file-through-the-browser-and-access-its-data-for-proce">Using Flask to load a txt file through the browser and access its data for processing</a>
  Do i need to add these lines too? I don't understand these</p>
  
  <pre><code>filename = secure_filename(file.filename) 
  
  # os.path.join is used so that paths work in every operating system
  file.save(os.path.join("wherever","you","want",filename))
  </code></pre>