I am little confused. I want to create API that can post image, and one dictionary along with that image. How can I do it ? for one image, I can do it like this. What if I want to post another variable which is not a file, lets say variable meta_data?
url = 'http://127.0.0.1:5000/im_size'
my_img = {'image': open('test.jpg', 'rb')}
r = requests.post(url, files=my_img)
What change should be in my API script as well which is as follow
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/im_size", methods=["POST"])
def process_image():
file = request.files['image']
# Read the image via file.stream
img = Image.open(file.stream)
return jsonify({'msg': 'success', 'size': [img.width, img.height]})
if __name__ == "__main__":
app.run(debug=True)