stable-diffusion-webui/modules/download_from_s3.py
Misha4ca228 89cea797b8 dev
2025-04-30 21:41:23 +03:00

23 lines
709 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import base64
from modules.s3 import s3_client
from urllib.parse import urlparse
def get_photo_base64(s3_url) -> str:
try:
s3_url = s3_url
parsed = urlparse(s3_url)
path_parts = parsed.path.lstrip('/').split('/', 1)
if len(path_parts) != 2:
raise ValueError("Не удалось извлечь bucket и key из URL.")
bucket_name, s3_key = path_parts
response = s3_client.get_object(Bucket=bucket_name, Key=s3_key)
image_data = response['Body'].read()
return base64.b64encode(image_data).decode('utf-8')
except Exception as e:
print(f"Ошибка при получении файла: {e}")
return ""