I reference this python send files to send file.
And this is my python frontend code. (I have a backend to receive the files["img"]
)
import requests
host = "http://example.org:5000"
with open("./test.png", "rb") as f:
r = requests.get(host, files={"img": f})
print(r.text)
So the structure would like this
{
"origin": ...,
"files": {
"img": "<censored...binary...data>"
},
"form": {},
"url": ...,
"args": {},
"headers": {
...
},
"data": ...
}
And I want to use k6 to testing it. I've read k6 file and write the script like this.
import http from "k6/http";
const img = open("./test.png", "b");
export default function() {
const params = {files: {"img": img}};
http.get("http://example.org:5000", params);
}
It seems that I did wrong. The request always failed. How can I fix that?