first push
This commit is contained in:
0
Core/ArvanStorage/__init__.py
Normal file
0
Core/ArvanStorage/__init__.py
Normal file
BIN
Core/ArvanStorage/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
Core/ArvanStorage/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
Core/ArvanStorage/__pycache__/arvan_storage.cpython-39.pyc
Normal file
BIN
Core/ArvanStorage/__pycache__/arvan_storage.cpython-39.pyc
Normal file
Binary file not shown.
60
Core/ArvanStorage/arvan_storage.py
Normal file
60
Core/ArvanStorage/arvan_storage.py
Normal 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
|
||||
)
|
||||
0
Core/__init__.py
Normal file
0
Core/__init__.py
Normal file
BIN
Core/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
Core/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
Core/__pycache__/admin.cpython-39.pyc
Normal file
BIN
Core/__pycache__/admin.cpython-39.pyc
Normal file
Binary file not shown.
BIN
Core/__pycache__/apps.cpython-39.pyc
Normal file
BIN
Core/__pycache__/apps.cpython-39.pyc
Normal file
Binary file not shown.
BIN
Core/__pycache__/models.cpython-39.pyc
Normal file
BIN
Core/__pycache__/models.cpython-39.pyc
Normal file
Binary file not shown.
3
Core/admin.py
Normal file
3
Core/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
Core/apps.py
Normal file
6
Core/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CoreConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'Core'
|
||||
0
Core/migrations/__init__.py
Normal file
0
Core/migrations/__init__.py
Normal file
BIN
Core/migrations/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
Core/migrations/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
33
Core/models.py
Normal file
33
Core/models.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.conf import settings
|
||||
from datetime import datetime, timezone, time
|
||||
from django.utils import timezone
|
||||
|
||||
import uuid
|
||||
|
||||
|
||||
# Create your views here.
|
||||
class BaseModel(models.Model):
|
||||
key = models.UUIDField(default=uuid.uuid4, editable=False, null=True, unique=True)
|
||||
create_date = models.DateTimeField(auto_now_add=True)
|
||||
modify_date = models.DateTimeField(auto_now=True)
|
||||
created_by = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
related_name="%(class)s_createdby",
|
||||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
modified_by = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="%(class)s_modifiedby",
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
trash = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
3
Core/tests.py
Normal file
3
Core/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
1
Core/views.py
Normal file
1
Core/views.py
Normal file
@@ -0,0 +1 @@
|
||||
from django.shortcuts import render
|
||||
Reference in New Issue
Block a user