how to send an numpy array or a pytorch Tensor through http post request using requests module and Flask
I have an image and I want to send it to the serve. I'm using requests module to perform simple post request as following(info is a dictionary):
    import requests

    print(type(info[&quot;array_image&quot;]))
    print(type(info[&quot;visual_features&quot;]))
    response = requests.post(&quot;url&quot;, data=info)

output :
&lt;class 'numpy.ndarray'&gt;
&lt;class 'torch.Tensor'&gt;

on the server side I'm trying to receive them as arrays at least:
from flask import Flask, request

@app.route('/path', methods=['POST'])
def function_name():
    visual_features = request.form['visual_features']
    array_image = request.form['array_image']
    print(type(array_image))
    print(type(visual_features))

output:
&lt;class 'str'&gt;
&lt;class 'str'&gt;

I want to get a bytes array to build the image, but what I'm getting is a string...
If I didn't find a way I'll encode arrays in bas64 and then decode it in the server...

Thanks to @praba230890 for giving me an easy to follow example.
I would still write the solution here down, since the provided link doesn't fit my case exactly.
import pickle
import io

bytes_image = pickle.dumps(info[&quot;array_image&quot;])
stream = io.BytesIO(bytes_image)
files = {&quot;bytes_image&quot;: stream}

info[&quot;array_image&quot;] = None

response = http.post(&quot;url&quot;, data=info, files=files)

and in the server side:
from flask import Flask, request

@app.route('/path', methods=['POST'])
def function_name():
    image = request.files.get('bytes_image')
    bytes_image = image.read()

if you want to get the image from a file, then:
requests.post(&quot;http://localhost:5000/predict&quot;,
                 files={&quot;file&quot;: open('&lt;PATH/TO/.jpg/FILE&gt;/cat.jpg','rb')})

The Solution I'm currently using:
remember info[&quot;array_image&quot;] is a numpy array, and info is a dictionary
    import io
    info[&quot;image_shape_width&quot;] = info[&quot;array_image&quot;].shape[0]
    info[&quot;image_shape_height&quot;] = info[&quot;array_image&quot;].shape[1]

    bytes_image = info[&quot;array_image&quot;].tobytes()
    stream = io.BytesIO(bytes_image)
    files = {&quot;bytes_image&quot;: stream}

    info[&quot;array_image&quot;] = None

    response = http.post(self.ip + &quot;path&quot;, data=info, files=files)

then receive it
    from flask import Flask, request
    import numpy as np

    @app.route('/path', methods=['POST'])
    def function_name():    
        bytes_image = request.files.get('bytes_image')
        bytes_image = bytes_image.read()
        array_image = np.frombuffer(bytes_image, dtype=dtype)
        shape = (int(request.form['image_shape_width']), int(request.form['image_shape_height']), 3)         
        array_image = np.reshape(array_image, shape)
                                       
        image = Image.fromarray(array_image)

