add bucket in CRD
All checks were successful
Build and Publish / build-release (push) Successful in 44s
All checks were successful
Build and Publish / build-release (push) Successful in 44s
This commit is contained in:
@@ -2,7 +2,6 @@ from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.openapi.utils import get_openapi
|
||||
from app.routers import documents
|
||||
from app.config import settings
|
||||
from app.logger import setup_logging
|
||||
from app.middleware.auth import AuthMiddleware
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from fastapi import Request
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
from starlette.responses import JSONResponse
|
||||
from app.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from app.enums import DocumentType
|
||||
|
||||
class DocumentMetadata(BaseModel):
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import os
|
||||
from pypdf import PdfReader
|
||||
from typing import Any
|
||||
|
||||
def discover_fields(pdf_path: str) -> list[dict]:
|
||||
"""
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
from app.routers import documents
|
||||
from app.routers import documents as documents
|
||||
|
||||
__all__ = ["documents"]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
from fastapi import APIRouter, HTTPException, UploadFile, File, Form, Request
|
||||
from typing import Optional
|
||||
from fastapi import APIRouter, HTTPException, UploadFile, File, Request
|
||||
from datetime import datetime
|
||||
|
||||
from app import s3, pdf, utils
|
||||
|
||||
23
app/s3.py
23
app/s3.py
@@ -49,16 +49,25 @@ def ensure_bucket_exists() -> None:
|
||||
def upload_file(file: UploadFile, s3_key: str, content_type: str, metadata: dict = None) -> str:
|
||||
"""Upload file to S3 with metadata"""
|
||||
client = get_client()
|
||||
|
||||
|
||||
# Read file content
|
||||
file.file.seek(0, os.SEEK_END)
|
||||
file_size = file.file.tell()
|
||||
file.file.seek(0)
|
||||
file_content = file.file.read()
|
||||
file.file.seek(0)
|
||||
|
||||
extra_args = {"ContentType": content_type}
|
||||
if metadata:
|
||||
extra_args["Metadata"] = metadata
|
||||
|
||||
client.upload_fileobj(
|
||||
file.file,
|
||||
settings.s3_bucket,
|
||||
s3_key,
|
||||
ExtraArgs=extra_args
|
||||
|
||||
client.put_object(
|
||||
Bucket=settings.s3_bucket,
|
||||
Key=s3_key,
|
||||
Body=file_content,
|
||||
ContentLength=file_size,
|
||||
ContentType=content_type,
|
||||
Metadata=metadata
|
||||
)
|
||||
return s3_key
|
||||
|
||||
|
||||
Reference in New Issue
Block a user