Skip to content

Commit d404597

Browse files
Update FileUploadParser docs. Closes #4167. [ci skip] (#4169)
1 parent 94863ee commit d404597

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

docs/api-guide/parsers.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ using the `APIView` class based views.
5151
return Response({'received data': request.data})
5252

5353
Or, if you're using the `@api_view` decorator with function based views.
54-
54+
5555
from rest_framework.decorators import api_view
5656
from rest_framework.decorators import parser_classes
5757

@@ -93,7 +93,9 @@ You will typically want to use both `FormParser` and `MultiPartParser` together
9393

9494
Parses raw file upload content. The `request.data` property will be a dictionary with a single key `'file'` containing the uploaded file.
9595

96-
If the view used with `FileUploadParser` is called with a `filename` URL keyword argument, then that argument will be used as the filename. If it is called without a `filename` URL keyword argument, then the client must set the filename in the `Content-Disposition` HTTP header. For example `Content-Disposition: attachment; filename=upload.jpg`.
96+
If the view used with `FileUploadParser` is called with a `filename` URL keyword argument, then that argument will be used as the filename.
97+
98+
If it is called without a `filename` URL keyword argument, then the client must set the filename in the `Content-Disposition` HTTP header. For example `Content-Disposition: attachment; filename=upload.jpg`.
9799

98100
**.media_type**: `*/*`
99101

@@ -105,6 +107,7 @@ If the view used with `FileUploadParser` is called with a `filename` URL keyword
105107

106108
##### Basic usage example:
107109

110+
# views.py
108111
class FileUploadView(views.APIView):
109112
parser_classes = (FileUploadParser,)
110113

@@ -115,6 +118,11 @@ If the view used with `FileUploadParser` is called with a `filename` URL keyword
115118
# ...
116119
return Response(status=204)
117120

121+
# urls.py
122+
urlpatterns = [
123+
# ...
124+
url(r'^upload/(?P<filename>[^/]+)$', FileUploadView.as_view())
125+
]
118126

119127
---
120128

0 commit comments

Comments
 (0)