-1

I used python flask function send_file to send image file from server to client. I get Http 200 response from the server with headers containing content information and response.text returns string of bytes. Currently both server and client is in local system. I want to access the file and save it in client side. Server code:

@app.route("/ss", methods=["POST"])
def ss():
    return send_file("chap.jpg",attachment_filename="chap.jpg")

Client code:

payload = {"image": image}
r = requests.post(http://127.0.0:5000/ss, files=payload)
print(r.text)

I tried converting the string from r.text to numpy array and save the array as jpg but i get TypeError for bad argument.

Unbanned
  • 11
  • 4

2 Answers2

0

you want to upload file ? {"imagge" : image is not a solution do like me :

import requests

image = 'image.jpg'

payload = {'image':(image, open(image, 'r'),'multipart/from-data')},

url = 'http://127.0.0:5000/ss'

r = requests.post(url, files=payload)

print r.text
Skiller Dz
  • 897
  • 10
  • 17
0

You need to access the binary content of the response and save it to a file.

with open('myfile.jpg', 'wb') as f:
    f.write(r.content)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895