|
4 | 4 | from inspect import signature
|
5 | 5 | from typing import Optional, Any, List
|
6 | 6 |
|
7 |
| -from fastapi import APIRouter, HTTPException, status, Depends |
| 7 | +from fastapi import APIRouter, HTTPException, status, Depends, UploadFile, File |
8 | 8 | from fastapi.responses import ORJSONResponse
|
9 | 9 | from fastapi_pagination import Page
|
10 | 10 | from fastapi_users import FastAPIUsers
|
|
18 | 18 | UserCreate, UserUpdate, UserItem, UserGroup, UserRead
|
19 | 19 | )
|
20 | 20 | from dataset_image_annotator.conf import settings
|
| 21 | +from dataset_image_annotator.core import upload_handler |
21 | 22 | from dataset_image_annotator.db import database
|
22 | 23 | from dataset_image_annotator.db.models import User
|
23 | 24 | from dataset_image_annotator.helpers import connect_to_db
|
@@ -105,3 +106,17 @@ async def get_user_groups(search: Optional[Json[Any]] = None, order_by: Optional
|
105 | 106 | return await core.get_user_groups(database, search, order_by)
|
106 | 107 |
|
107 | 108 | raise HTTPException(status_code=403)
|
| 109 | + |
| 110 | + |
| 111 | +@router.post('/raw-file', response_class=ORJSONResponse, tags=['Admin']) |
| 112 | +@handle_exceptions |
| 113 | +async def upload_raw_file(image_file: UploadFile = File(...)): |
| 114 | + if not image_file.filename: |
| 115 | + raise HTTPException(status_code=400, detail='Missing file') |
| 116 | + |
| 117 | + try: |
| 118 | + response = await upload_handler.handle_raw_file(database, image_file) |
| 119 | + except TimeoutError as e: |
| 120 | + raise HTTPException(status_code=504, detail=str(e)) |
| 121 | + |
| 122 | + return response |
0 commit comments