first push

This commit is contained in:
2026-01-18 12:05:56 +03:30
commit cdbb2e11ed
109 changed files with 3083 additions and 0 deletions

View File

Binary file not shown.

View File

@@ -0,0 +1,60 @@
import io
import boto3
import logging
from PIL import Image
from botocore.exceptions import ClientError
from django.http import HttpResponse
import base64
# ARVAN_STORAGE_URL = "https://dmstore.s3.ir-thr-at1.arvanstorage.com/36bba98f-a813-4667-bd60-33aef708bcba.jpg?AWSAccessKeyId=d5739a44-e663-4f43-99f3-13121a62a9e6&Signature=KpBpHBtAS77Y3hHx53g6bmjlGpc%3D&Expires=1651552380"
def connect():
logging.basicConfig(level=logging.INFO)
try:
s3_resource = boto3.resource(
's3',
endpoint_url='https://s3.ir-thr-at1.arvanstorage.com',
aws_access_key_id='d5739a44-e663-4f43-99f3-13121a62a9e6',
aws_secret_access_key='bcc8bc64cac2de7711f8c5d3a4b0123f28319f97fb9e0e9b8fbcfd7465678cdb'
)
except Exception as exc:
logging.info(exc)
return s3_resource
def get_bucket_list():
s3_resource = connect()
li = []
try:
for bucket in s3_resource.buckets.all():
logging.info(f'bucket_name: {bucket.name}')
li.append(bucket.name)
except ClientError as exc:
logging.error(exc)
return li[0]
def upload_object(image_data, bucket_name, object_name):
resource_connect = connect()
s3_resource = resource_connect
bucket = s3_resource.Bucket(bucket_name)
buffer = io.BytesIO()
imgdata = base64.b64decode(image_data)
img = Image.open(io.BytesIO(imgdata))
new_img = img.resize((500, 500)) # x, y
new_img.save(buffer, format="PNG")
img_b64 = base64.b64encode(buffer.getvalue())
with open(object_name, "wb") as fh:
fh.write(base64.standard_b64decode(img_b64))
# base64.standard_b64decode(image_data)
with open(object_name, "rb") as fh:
bucket.put_object(
ACL='public-read',
Body=fh,
Key=object_name
)