Last active
August 8, 2023 11:28
-
-
Save Ichinga-Samuel/5cd277c0ced5b8259f942c253e06d7eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastapi import FastAPI, File, UploadFile, Depends | |
from filestore import LocalStorage, Result | |
app = FastAPI() | |
# local storage instance for single file upload | |
loc = LocalStorage(name='book', required=True) | |
# local storage instance for multiple file upload with a maximum of 2 files from a single field | |
loc2 = LocalStorage(name='book', required=True, count=2) | |
# local storage instance for multiple file uploads from different fields | |
multiple_local = LocalStorage(fields=[{'name': 'author', 'max_count': 2}, {'name': 'book', 'max_count': 1}]) | |
@app.post('/upload_book') | |
async def upload_book(book=Depends(loc), model=Depends(loc.model)): | |
return book.result | |
@app.post('/local_multiple', name='upload', openapi_extra={'form': {'multiple': True}}) | |
async def local_multiple(model=Depends(multiple_local.model), loc=Depends(multiple_local)) -> Result: | |
return loc.result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment