I have created FLASK web service to upload an image but I'm getting an error when I try to call it using POSTMAN.
Getting an error
400 Bad Request: KeyError: 'file1'
But I am sure I have same key name at both the places.
My Code:
from flask import Flask, request
from scipy.stats import wasserstein_distance
import numpy as np
import cv2
from imutils import paths
from werkzeug.utils import secure_filename
app = Flask(__name__)
@app.route("/img", methods=['POST'])
def search():
file = request.files['file1']
filename = secure_filename(file.filename)
file.save(filename)
images = list(paths.list_images("data"))
query_image = cv2.imread(filename)
query_image = cv2.cvtColor(query_image, cv2.COLOR_BGR2GRAY)
q_hist = get_histogram(query_image)
hist = []
for i in images:
image = cv2.imread(i)
# convert the images to grayscale
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
s_hist = get_histogram(image)
dist = wasserstein_distance(q_hist, s_hist)
hist.append(dist)
x = min(hist)
print(hist)
if x > 2:
return "Image Not Found"
else:
idx = hist.index(x)
matched_img = images[idx]
return des[matched_img]
if __name__ == '__main__':
app.run(debug=True)
This is how I am calling the web service using postman
Headers
How can I resolve this?

