服务端
@app.post("/SegCrop")
async def SegDD(imgID: str = Form(...),SegDD: str = Form(...),file: UploadFile = File(...)):
# imgID = item.imgID
print("imgID---->",imgID)
print("SegDD---->",SegDD)
contents = await file.read()
# with open(file.filename, 'wb') as f:
with open("filename.jpg", 'wb') as f:
f.write(contents)
await file.close()
客户端
img=cv2.imread("xx.jpg")
success, encoded_image = cv2.imencode(".jpg", img)
# 将数组转为bytes
img_bytes = encoded_image.tobytes()
# headers = {"Content-type": "application/json" "image/png"}
headers = {"Content-type": "image/jpeg"}
url = 'http://18.0.44.100:9007/SegCrop'
file = {'file': img_bytes}
data={"imgID":1000,"SegDD":True}
resp = requests.post(url=url,files=file,data=data)
print(resp.json())
参考文章
- https://blog.csdn.net/m0_37400316/article/details/125994185