Issue
I want to pass images through POST method in POSTMAN but I get None type response in the line request.files['image']
I have tried a number of different things but I am not able to solve the problem.
from flask import Flask,jsonify
from flask import request
import face_recognition
import json
app = Flask(__name__)
@app.route('/')
def index():
return ''
@app.route('/valid_faces', methods=['POST'])
def POST():
if request.method == 'POST':
# getting the images url from the request
print('....')
name1 = request.files['file'] if request.files.get('file') else None
print('....')
print (name1) # name2 = request.form.get('name2')
# map the url to the ones in the folder images
firstImage = name1
# loading the image inside a variable
firstImage = face_recognition.load_image_file(firstImage)
result=face_recognition.face_locations(firstImage)
if result:
# x={'valid_faces':True}
# return jsonify(x)
return "True"
else:
# x={'valid_faces':False}
# return jsonify(x)
return "False"
if __name__ == "__main__":
app.run(debug=True)
Solution
If you wish to append a file to a postman call it needs to be added to the body.
Check form-data
and select file
instead of text
. You can now select a file with the windows file explorer.
To obtain the given file use the request
package.
file = request.files['file']
The index has to be the same string you specified within the postman body data.
Answered By - ZKDev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.