ФУНКЦИИ - МЕЖПРОЕКТНАЯ КОММУНИКАЦИЯ: подтверждение файловых загрузок через внутренний storage
This commit is contained in:
@@ -22,7 +22,7 @@ class S3Storage(S3Boto3Storage):
|
||||
|
||||
"""S3 storage class to generate presigned URLs for S3 objects"""
|
||||
|
||||
def __init__(self, request=None, **kwargs):
|
||||
def __init__(self, request=None, is_server=False, use_internal_endpoint=False, **kwargs):
|
||||
# Get the AWS credentials and bucket name from the environment
|
||||
self.aws_access_key_id = os.environ.get("AWS_ACCESS_KEY_ID")
|
||||
# Use the AWS_SECRET_ACCESS_KEY environment variable for the secret key
|
||||
@@ -36,19 +36,26 @@ class S3Storage(S3Boto3Storage):
|
||||
# Use the SIGNED_URL_EXPIRATION environment variable for the expiration time (default: 3600 seconds)
|
||||
self.signed_url_expiration = int(os.environ.get("SIGNED_URL_EXPIRATION", "3600"))
|
||||
|
||||
self.use_internal_endpoint = bool(is_server or use_internal_endpoint)
|
||||
|
||||
if os.environ.get("USE_MINIO") == "1":
|
||||
# Determine protocol based on environment variable
|
||||
if os.environ.get("MINIO_ENDPOINT_SSL") == "1":
|
||||
endpoint_protocol = "https"
|
||||
else:
|
||||
endpoint_protocol = request.scheme if request else "http"
|
||||
endpoint_protocol = request.scheme if request and not self.use_internal_endpoint else "http"
|
||||
|
||||
endpoint_url = self.aws_s3_endpoint_url
|
||||
if request and not self.use_internal_endpoint:
|
||||
endpoint_url = f"{endpoint_protocol}://{request.get_host()}"
|
||||
|
||||
# Create an S3 client for MinIO
|
||||
self.s3_client = boto3.client(
|
||||
"s3",
|
||||
aws_access_key_id=self.aws_access_key_id,
|
||||
aws_secret_access_key=self.aws_secret_access_key,
|
||||
region_name=self.aws_region,
|
||||
endpoint_url=(f"{endpoint_protocol}://{request.get_host()}" if request else self.aws_s3_endpoint_url),
|
||||
endpoint_url=endpoint_url,
|
||||
config=boto3.session.Config(signature_version="s3v4"),
|
||||
)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user