minio이미지 업로드 기능 테스트
This commit is contained in:
0
obs_minio/__init__.py
Normal file
0
obs_minio/__init__.py
Normal file
3
obs_minio/admin.py
Normal file
3
obs_minio/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
obs_minio/apps.py
Normal file
6
obs_minio/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ObsMinioConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'obs_minio'
|
0
obs_minio/migrations/__init__.py
Normal file
0
obs_minio/migrations/__init__.py
Normal file
3
obs_minio/models.py
Normal file
3
obs_minio/models.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
3
obs_minio/tests.py
Normal file
3
obs_minio/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
8
obs_minio/urls.py
Normal file
8
obs_minio/urls.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = 'obs_minio'
|
||||
|
||||
urlpatterns = [
|
||||
path('upload/', views.upload_image, name='upload_image'),
|
||||
]
|
47
obs_minio/views.py
Normal file
47
obs_minio/views.py
Normal file
@ -0,0 +1,47 @@
|
||||
import uuid
|
||||
from django.http import JsonResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from minio import Minio
|
||||
from minio.error import S3Error
|
||||
import urllib3
|
||||
|
||||
# MinIO 설정
|
||||
MINIO_ENDPOINT = 'minio.icurfer.com:9000'
|
||||
MINIO_ACCESS_KEY = 'h5gOXcQieSE0kReVlpDa'
|
||||
MINIO_SECRET_KEY = '2S5vtc7DtrnUjqsAO6CF3kPVEqDtqmHgnt3OPIPY'
|
||||
BUCKET_NAME = 'butler-ddochi-image'
|
||||
|
||||
@csrf_exempt
|
||||
def upload_image(request):
|
||||
print("이미지업로드 동작시작")
|
||||
if request.method == 'POST' and 'image' in request.FILES:
|
||||
image = request.FILES['image']
|
||||
unique_filename = f"uploads/{uuid.uuid4()}_{image.name}"
|
||||
|
||||
# MinIO 클라이언트 생성
|
||||
client = Minio(
|
||||
MINIO_ENDPOINT,
|
||||
access_key=MINIO_ACCESS_KEY,
|
||||
secret_key=MINIO_SECRET_KEY,
|
||||
secure=True,
|
||||
http_client=urllib3.PoolManager(cert_reqs='CERT_NONE') # SSL 검증 비활성화
|
||||
)
|
||||
|
||||
try:
|
||||
# MinIO에 파일 업로드
|
||||
client.put_object(
|
||||
bucket_name=BUCKET_NAME,
|
||||
object_name=unique_filename,
|
||||
data=image,
|
||||
length=image.size,
|
||||
content_type=image.content_type
|
||||
)
|
||||
|
||||
# Presigned URL 생성
|
||||
presigned_url = client.presigned_get_object(BUCKET_NAME, unique_filename)
|
||||
return JsonResponse({"url": presigned_url}, status=201)
|
||||
|
||||
except S3Error as e:
|
||||
return JsonResponse({"error": str(e)}, status=500)
|
||||
|
||||
return JsonResponse({"error": "Invalid request"}, status=400)
|
Reference in New Issue
Block a user