jira-9 and jira-12 sendgrid and upload images in alibaba bucket

This commit is contained in:
jain
2023-06-29 11:40:04 +05:30
parent f0a2a4bd4b
commit 9d7f265f40
17 changed files with 160 additions and 35 deletions

13
guardian/utils.py Normal file
View File

@ -0,0 +1,13 @@
import oss2
from django.conf import settings
import tempfile
def upload_image_to_alibaba(image, filename):
# Save the image object to a temporary file
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_file.write(image.read())
auth = oss2.Auth(settings.ALIYUN_OSS_ACCESS_KEY_ID, settings.ALIYUN_OSS_ACCESS_KEY_SECRET)
bucket = oss2.Bucket(auth, settings.ALIYUN_OSS_ENDPOINT, settings.ALIYUN_OSS_BUCKET_NAME)
# Upload the temporary file to Alibaba OSS
bucket.put_object_from_file(filename, temp_file.name)
return f"https://{settings.ALIYUN_OSS_BUCKET_NAME}.{settings.ALIYUN_OSS_ENDPOINT}/{filename}"