'How can I upload files in Postman?
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 1:[1]
In my case Postman set empty first value for FileStorage object in request.files . You can check this using:
print(str(request.files))
And in case of empty index instead
file = request.files['file']
try to use
file = request.files['']
Solution 2:[2]
In Postman, do the following:
- Set the method to POST
- Set the body type to form-data
- Establish Key/Value pairs for input. Set the value for the Key to "file"
- Mouse over the Key field and choose Text or File from the drop-down menu
- Click Send to process the request
Solution 3:[3]
follow this process: https://i.stack.imgur.com/GGm4I.png
- Set Method to POST
- Change body tab to form-data
- Set key
- in Value, hover, you can see file/text. in here select file
- Select file you want to upload.
- Send request.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bhramari |
| Solution 2 | |
| Solution 3 | cedric |
