0

I'm using Postman to help me generate an HttpRequest. I want to send an image blob (POST request) to my Flask server to be processed with OpenCV.

When I manually select the file to send as binary data (i.e. in Postman: Body -> binary -> choose files), I can then access the blob in Flask via request.data. However, when I try to send as form-data, I'm not sure how to access the blob and I get bad requests or other errors.

I'm sending the request as: (in Postman) Body -> form-data -> Key: "image", Value: . In Flask I'm trying to access the image via request.form['image'], according to what I read here., but this returns status 400 bad request.

Screenshot of Postman

Python code snippet:

import cv2 as cv
import numpy as np
from flask import Flask, request

app = Flask(__name__)

@app.route("/croprect", methods = ["POST"])
def crop_rect():
    r = request
    blob = r.form['image']
        nparr = np.fromstring(blob, np.uint16)
        img = cv.imdecode(nparr, cv.IMREAD_COLOR)

if __name__ == "__main__":
    app.run()

Edit: I have already checked the answers in this post. I've tried request.form.get("image"), request.args.get("image", ""), but none of these are working and I'm definitely misunderstanding which method to use.

Matheus Leão
  • 417
  • 4
  • 12

0 Answers0