6

I'm using Locust.io to load test a python/django website that accepts image upload::

headers = {'content-type': 'multipart/form-data'}
image = open('img.jpg', 'rb')
payload = {'id': self.id}
files = {'photo': image}    
upload_result = self.client.post("/image/", data=payload, files=files, headers=headers)

When I use the above I see request.FILES in Django is None. However when I use POSTMAN instead of Locust to do the same thing, I get the files object in request in Django.

server.py

photo = request.FILES.get('photo')
id = request.POST.get('id')
form = PhotosModelForm(request.POST, request.FILES)

How do I send the file in the Locust HTTP client request along with some POST data?

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
Anuj Acharya
  • 546
  • 2
  • 9
  • 18
  • 1
    Locust uses `requests` as a transport library. The answer [here](https://stackoverflow.com/questions/45881885/upload-image-through-form-data-using-python-requests) should work (assuming your Django site receives the file as `multipart/form-data`) – yorodm Jan 17 '19 at 18:32

0 Answers0