Include Content-disposition header for Django FileUpload

Viewed 4177

I defined an API endpoint which accepts a file (e.g. using Django REST Framework). In Django, the content disposition header can be used when inspecting the response.

https://docs.djangoproject.com/en/1.11/ref/request-response/#telling-the-browser-to-treat-the-response-as-a-file-attachment

Now, if we want to set the header when testing the endpoint, how do I include this header using REST-Framework's APITestCase?

What I tried so far is, but it does not seem to accept the headers.

class TestSaleViews(APITestCase):
    def test_sale_detail_view(self):
        f = create_named_temporary_file()
        files = {'archive': f}
        basename = os.path.basename(f.name)
        headers = {
            'content-disposition': 'attachment; filename={}'.format(basename),
        }
        response = self.client.post(url, files, format='multipart', **headers)
1 Answers
Related