from starlette.staticfiles import StaticFiles import os from os.path import dirname, abspath, join def get_db(): db = SessionLocal() try: yield db finally: db.close() models.Base.metadata.create_all(bind=engine) router.mount("/static", StaticFiles(directory="static"), name="static") dirname = dirname(dirname(abspath(__file__))) images_path = join(dirname, '/static') @router.post("/filmo/") def create_filmo(title: str, desc: str, status: int, file: UploadFile = File(...), db: Session = Depends(get_db)): extension = file.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension: return "Image must be jpg or png format!"
from pathlib import Path from fastapi import APIRouter from starlette.staticfiles import StaticFiles frontend = APIRouter() frontend.mount( "/static", StaticFiles(directory=str(Path(__file__).parent / 'daqbrokerfrontend')), name="static")
from fastapi import APIRouter, Request, Form, File, UploadFile from fastapi.responses import HTMLResponse, FileResponse from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates import aiofiles import uuid import os from db.db import fetch_query, insert_command from models.image import Image app_v1 = APIRouter() app_v1.mount("/static", StaticFiles(directory="static"), name="static") templates = Jinja2Templates(directory="templates") @app_v1.get("/") async def home(request: Request): return templates.TemplateResponse("index.html", {"request": request}) @app_v1.post("/grabimage") async def read_item(file_name: str = Form(None), keywords: str = Form(None)): record = fetch_query(file_name, keywords) return FileResponse(f'static/{record[0][0]}') @app_v1.post("/uploadimg") async def upload_image(img: UploadFile = File(...), tags: str = Form(None)):
from fastapi import APIRouter from api.v1.endpoints import ekyc from fastapi.staticfiles import StaticFiles api_router = APIRouter() api_router.include_router(ekyc.router, prefix='/ekyc', tags=['ekyc']) api_router.mount("/ui", StaticFiles(directory="./api/build"), name="ui_build") api_router.mount("/static", StaticFiles(directory="./api/build/static"), name="ui_static")