0

I currently have code that I am using to send a single image to a Flask server over HTTP using the Python request library. This is not an image that originates from a file, it's an image that has been opened using OpenCV.

Currently, the code I am using to send the image to the Flask server on the client side is:

    adress = (http address)

    content_type = 'image/jpeg'
    headers = {'content-type': content_type}

    _, img_encoded = cv2.imencode('.jpeg', image)

    response = requests.post(address, data=img_encoded.tostring(), headers=headers,
                                 auth=HTTPBasicAuth(username, password))

And on the server side, the image is "received" in the following way:


    r = request
    nparr = np.fromstring(r.data, np.uint8)
    img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)


I would now like to define a new route where I send two images instead of one to the server (the images have to be in the same call because I am performing a single operation that requires both of them at the same time), but I am having no luck with extending the current code to work with two images. I tried encoding two images, and having the data sent in the requests be

data=[img_1_encoded.tostring(), img_2_encoded.tostring()]

but did not have much luck with that.

Any help would be greatly appreciated!

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • Maybe a dup: https://stackoverflow.com/q/18179345/5378816 – VPfB Jun 20 '23 at 14:29
  • @VPfB yes I previously saw the same post, however they send actual files over HTTP whereas I am basically sending images in the form of numpy arrays – danroggy Jun 21 '23 at 07:13
  • 1
    Does this answer your question? [Uploading multiple files in a single request using python requests module](https://stackoverflow.com/questions/18179345/uploading-multiple-files-in-a-single-request-using-python-requests-module) – Christoph Rackwitz Jun 21 '23 at 09:33
  • definitely a dup. voting to close. this really hasn't got anything to do with opencv since that part of the code seems to work. it's _purely_ about how to `POST` multiple files. – Christoph Rackwitz Jun 21 '23 at 09:33

0 Answers0