Skip to content

Commit

Permalink
files documentation to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalik committed Jan 2, 2025
1 parent f91e321 commit 39f40b3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions docs/docs/guides/input/file-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from ninja import NinjaAPI, File
from ninja.files import UploadedFile

@api.post("/upload")
def upload(request, file: UploadedFile = File(...)):
def upload(request, file: File[UploadedFile]):
data = file.read()
return {'name': file.name, 'len': len(data)}
```
Expand Down Expand Up @@ -36,7 +36,7 @@ from ninja import NinjaAPI, File
from ninja.files import UploadedFile

@api.post("/upload-many")
def upload_many(request, files: List[UploadedFile] = File(...)):
def upload_many(request, files: File[List[UploadedFile]]):
return [f.name for f in files]
```

Expand Down Expand Up @@ -96,7 +96,7 @@ If you would like the file input to be optional, all that you have to do is to p

```python
@api.post('/users')
def create_user(request, details: Form[UserDetails], avatar: UploadedFile = File(None)):
def create_user(request, details: Form[UserDetails], avatar: File[UploadedFile] = None):
user = add_user_to_database(details)
if avatar is not None:
set_user_avatar(user)
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/tutorial/other/crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ See the recipe below for handling the file upload (when using Django models):
from ninja import UploadedFile, File

@api.post("/employees")
def create_employee(request, payload: EmployeeIn, cv: UploadedFile = File(...)):
def create_employee(request, payload: EmployeeIn, cv: File[UploadedFile]):
payload_dict = payload.dict()
employee = Employee(**payload_dict)
employee.cv.save(cv.name, cv) # will save model instance as well
Expand All @@ -75,7 +75,7 @@ from ninja import UploadedFile, File
STORAGE = FileSystemStorage()

@api.post("/upload")
def create_upload(request, cv: UploadedFile = File(...)):
def create_upload(request, cv: File[UploadedFile]):
filename = STORAGE.save(cv.name, cv)
# Handle things further
```
Expand Down
4 changes: 2 additions & 2 deletions tests/demo_project/multi_param/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_multi_form_body(
@router.post("/test-multi-body-form-file", response=ResponseData, by_alias=True)
def test_multi_body_form_file(
request,
file: UploadedFile = File(...),
file: File[UploadedFile],
i: int = Body(...),
s: str = Form("a-str"),
data: TestData4 = Body(..., **test_data4_extra),
Expand All @@ -189,7 +189,7 @@ def test_multi_body_form_file(
@router.post("/test-multi-form-body-file", response=ResponseData, by_alias=True)
def test_multi_form_body_file(
request,
file: UploadedFile = File(...),
file: File[UploadedFile],
i: int = Form(...),
s: str = Body("a-str"),
data: TestData4 = Form(..., **test_data4_extra),
Expand Down

0 comments on commit 39f40b3

Please sign in to comment.