Tests de PDFs con Minio los pdfs se guardan una sola vez ahora
This commit is contained in:
@@ -8,12 +8,13 @@ import os
|
||||
import boto3
|
||||
from botocore.client import Config
|
||||
import uuid
|
||||
from app.core import config as app_config
|
||||
# S3/MinIO configuration
|
||||
S3_ENDPOINT = os.getenv('MINIO_ENDPOINT', 'http://localhost:9000')
|
||||
S3_ACCESS_KEY = os.getenv('MINIO_ACCESS_KEY', 'minioadmin')
|
||||
S3_SECRET_KEY = os.getenv('MINIO_SECRET_KEY', 'minioadmin')
|
||||
S3_IMAGE_BUCKET = os.getenv('MINIO_IMAGE_BUCKET', 'images')
|
||||
S3_PDF_BUCKET = os.getenv('MINIO_PDF_BUCKET', 'pdfs')
|
||||
S3_ENDPOINT = app_config.MINIO_ENDPOINT
|
||||
S3_ACCESS_KEY = app_config.MINIO_ACCESS_KEY
|
||||
S3_SECRET_KEY = app_config.MINIO_SECRET_KEY
|
||||
S3_IMAGE_BUCKET = app_config.MINIO_IMAGE_BUCKET
|
||||
S3_PDF_BUCKET = app_config.MINIO_PDF_BUCKET
|
||||
|
||||
s3_client = boto3.client(
|
||||
's3',
|
||||
@@ -1696,14 +1697,17 @@ def export_inspection_to_pdf(
|
||||
# ...existing code for PDF generation...
|
||||
doc.build(elements)
|
||||
buffer.seek(0)
|
||||
# Guardar localmente para depuración
|
||||
with open(f"/tmp/test_inspeccion_{inspection_id}.pdf", "wb") as f:
|
||||
f.write(buffer.getvalue())
|
||||
now = datetime.now()
|
||||
folder = f"{now.year}/{now.month:02d}"
|
||||
filename = f"inspeccion_{inspection_id}_{inspection.vehicle_plate or 'sin-patente'}.pdf"
|
||||
s3_key = f"{folder}/{filename}"
|
||||
# Subir PDF a S3/MinIO
|
||||
buffer.seek(0) # Asegura que el puntero esté al inicio
|
||||
s3_client.upload_fileobj(buffer, S3_PDF_BUCKET, s3_key, ExtraArgs={"ContentType": "application/pdf"})
|
||||
pdf_url = f"{S3_ENDPOINT}/{S3_PDF_BUCKET}/{s3_key}"
|
||||
# Guardar pdf_url en la inspección
|
||||
inspection.pdf_url = pdf_url
|
||||
db.commit()
|
||||
return {"pdf_url": pdf_url}
|
||||
|
||||
Reference in New Issue
Block a user