Add S3 presigned URL direct upload (presign → PUT → confirm)
- Add presign endpoint: POST /api/v1/transactions/presign - Add confirm endpoint: POST /api/v1/transactions/confirm - Add generate_presigned_put_url() to MinIO service with public endpoint support - Add public_endpoint field to MinioConfig - Keep legacy /upload endpoint as fallback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -39,3 +39,23 @@ def upload_image(file_bytes: bytes, original_filename: str) -> str:
|
||||
ContentType=content_type,
|
||||
)
|
||||
return object_key
|
||||
|
||||
|
||||
def generate_presigned_put_url(object_key: str) -> str:
|
||||
client = _get_client()
|
||||
url: str = client.generate_presigned_url(
|
||||
"put_object",
|
||||
Params={
|
||||
"Bucket": settings.minio.bucket,
|
||||
"Key": object_key,
|
||||
},
|
||||
ExpiresIn=300,
|
||||
)
|
||||
# Replace internal endpoint with public endpoint
|
||||
if settings.minio.public_endpoint:
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
||||
internal = urlparse(settings.minio.endpoint)
|
||||
public = urlparse(settings.minio.public_endpoint)
|
||||
url = url.replace(f"{internal.scheme}://{internal.netloc}", f"{public.scheme}://{public.netloc}", 1)
|
||||
return url
|
||||
|
||||
Reference in New Issue
Block a user