Found the solution by myself: Just add a list of files to the files block.
from django.core.files.base import ContentFile
from rest_framework.test import APIClient
data = dict()
data['files'] = [
ContentFile(content='contentabc', name='filenameA.txt'),
ContentFile(content='contentxyz', name='filenameB.txt')
]
client = APIClient()
client.post('/testurl/', data=data, format='multipart')
Am Mittwoch, 5. Dezember 2018 13:00:49 UTC+1 schrieb Tobias:
>
> Hello,
>
> our api requires to upload multiple files on the same fieldname:
>
> Content-Type:
> multipart/form-data;boundary=------FormBoundaryShouldDifferAtRuntime
>
> ------FormBoundaryShouldDifferAtRuntime
> Content-Disposition: form-data; name="*files*"; filename="*filenameA.pdf*"
> Content-Type: application/pdf
>
> [content]
> ------FormBoundaryShouldDifferAtRuntime
> Content-Disposition: form-data; name="*files*"; filename="*filenameB.pdf*"
> Content-Type: application/pdf
>
> [content]
> ------FormBoundaryShouldDifferAtRuntime--
>
> At the moment i am not able to write a test with two files on the same
> files key. MultiValueDict does not work with APIClient.post(). Any
> recommendations?
>
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-rest-framework/4f184fd9-4b69-4276-acb3-e1efa50353e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.