feat: Presigned URL API 및 OpenTelemetry trace 추가
Some checks failed
Build And Test / build-and-push (push) Has been cancelled
Some checks failed
Build And Test / build-and-push (push) Has been cancelled
- Presigned URL API 추가 (MinIO/S3 private 버킷 지원) - OpenTelemetry trace 설정 추가 (DEBUG=False 시 활성화) - requirements.txt에 opentelemetry 패키지 추가 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -2,6 +2,9 @@
|
||||
|
||||
import os
|
||||
import re
|
||||
import boto3
|
||||
from botocore.client import Config
|
||||
from django.conf import settings
|
||||
from rest_framework import generics, viewsets, permissions, status
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
from rest_framework.response import Response
|
||||
@ -371,4 +374,40 @@ class AttachmentDeleteView(APIView):
|
||||
attachment.delete()
|
||||
|
||||
logger.info(f"Attachment '{original_name}' deleted from post {post_pk} by {username}.")
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
|
||||
class PresignedUrlView(APIView):
|
||||
"""Presigned URL 생성 (MinIO/S3)"""
|
||||
permission_classes = [permissions.AllowAny]
|
||||
|
||||
def get_s3_client(self):
|
||||
"""S3 클라이언트 생성"""
|
||||
return boto3.client(
|
||||
's3',
|
||||
endpoint_url=settings.AWS_S3_ENDPOINT_URL,
|
||||
aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
|
||||
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
|
||||
config=Config(signature_version='s3v4'),
|
||||
region_name=settings.AWS_S3_REGION_NAME,
|
||||
)
|
||||
|
||||
def get(self, request, object_key):
|
||||
"""GET presigned URL 생성"""
|
||||
try:
|
||||
s3_client = self.get_s3_client()
|
||||
presigned_url = s3_client.generate_presigned_url(
|
||||
'get_object',
|
||||
Params={
|
||||
'Bucket': settings.AWS_STORAGE_BUCKET_NAME,
|
||||
'Key': object_key,
|
||||
},
|
||||
ExpiresIn=3600, # 1시간 유효
|
||||
)
|
||||
return Response({'url': presigned_url})
|
||||
except Exception as e:
|
||||
logger.error(f"Presigned URL 생성 실패: {e}")
|
||||
return Response(
|
||||
{'detail': 'Presigned URL 생성 실패'},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
)
|
||||
Reference in New Issue
Block a user