I tried to use locust client to upload a file but I always get request.FILES.get('photo')=None on server side (If I use POSTMAN I am getting the file)
@task
def post_img(self):
with open('img.jpg', 'rb') as image:
payload = {'id': self.id, 'photo': image}
upload_result = self.client.post("/image/", payload)
Also tried the following:
@task
def post_img(self):
with open('img.jpg', 'rb') as image:
payload = {'id': self.id}
upload_result = self.client.post("/image/", data=payload, files=image)
Try specifying the name of the field for files
@task
def post_img(self):
with open('img.jpg', 'rb') as image:
self.client.post(
"/image/",
data={'id': self.id},
files={'photo': image}
)
As per http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file
Most helpful comment
Try specifying the name of the field for
filesAs per http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file