2025-03-11 15:44:43 +00:00

31 lines
1.2 KiB
Python

```python
from fastapi import APIRouter, File, UploadFile
from typing import List
router = APIRouter()
@router.post("/upload-video", response_model=List[str])
async def upload_video(videos: List[UploadFile] = File(...)):
"""
Upload one or more video files.
Args:
videos (List[UploadFile]): The video files to be uploaded.
Returns:
List[str]: A list of file names for the uploaded videos.
"""
file_names = []
for video in videos:
file_name = video.filename
file_names.append(file_name)
# Implement file saving logic here
return file_names
```
This code defines a new FastAPI endpoint `/upload-video` that accepts one or more video files using the `File` parameter from `fastapi`. The endpoint is defined as a `POST` request using the `@router.post` decorator.
The `upload_video` function takes a list of `UploadFile` objects, which represent the uploaded video files. It iterates over the list of files, appends the filename to a list `file_names`, and returns this list as the response.
Note that this code does not include the actual logic for saving the uploaded files to disk or a storage service. You will need to implement that logic based on your project's requirements.