Locust: sending POST image in client.post() never receives Request.FILES

Created on 7 Dec 2015  ยท  1Comment  ยท  Source: locustio/locust

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)
bug

Most helpful comment

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

>All comments

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

Was this page helpful?
0 / 5 - 0 ratings