Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sending POST image in client.post() never receives Request.FILES #364

Closed
anujacharya1 opened this issue Dec 7, 2015 · 1 comment
Closed
Labels

Comments

@anujacharya1
Copy link

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)
@justiniso justiniso added the bug label Apr 2, 2016
@darrenlucas
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants