My post request is like this:
POST http://localhost:5000/upload
Content-Type: text/csv
Filename: /path/to/file/filename.csv
I want to receive this file in my code.I have found that the file is received in request.files['file']
in case my file is uploaded using html form where the name associated with the uploaded file is 'file'
. But since I am sending the file in the post method of my API, I have no name associated directly to my file object. SO how do I accept the file in my python flask code?
The code I am using is like this but the request.files
object seems empty after the API hit.
class FileInput(Resource):
def post(self):
conn = e.connect()
if 'file' not in request.files:
return "No file part."
file = request.files['file']
if file.filename == '':
return "No File Selected"
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return "File Input Successful."
return "File Input Unsuccessful."