Added s3 storage

This commit is contained in:
Mawoka
2023-04-18 19:22:26 +02:00
parent 345dd4583d
commit a0b02ec9c3
9 changed files with 1026 additions and 653 deletions
+4 -1
View File
@@ -5,7 +5,7 @@
import re
from fastapi import APIRouter, HTTPException
from fastapi.responses import StreamingResponse
from fastapi.responses import StreamingResponse, RedirectResponse
from classquiz.config import settings, storage
from classquiz.storage.errors import DownloadingFailedError
@@ -21,6 +21,9 @@ file_regex = r"^[a-z0-9]{8}-[a-z0-9-]{27}--[a-z0-9-]{36}$"
async def download_file(file_name: str):
if not re.match(file_regex, file_name):
raise HTTPException(status_code=400, detail="Invalid file name")
if storage.backend == "s3":
print("redir")
return RedirectResponse(url=await storage.get_url(file_name, 300))
try:
download = await storage.download(file_name)
except DownloadingFailedError: