import --> download & upload warehouise exit doc and that status
This commit is contained in:
@@ -1,4 +1,31 @@
|
||||
import boto3
|
||||
from botocore.exceptions import NoCredentialsError
|
||||
|
||||
STORAGE_ENDPOINT = 'https://s3.rasadyar.com/rasaddam'
|
||||
STORAGE_BUCKET_NAME = 'ticket-rasadyar'
|
||||
STORAGE_ACCESS_KEY = "zG3ewsbYsTqCmuws"
|
||||
STORAGE_SECRET_KEY = 'RInUMB78zlQZp6CNf8+sRoSh2cNDHcGQhXrLnTJ1AuI='
|
||||
|
||||
|
||||
def upload_to_storage(file_obj, file_name):
|
||||
try:
|
||||
s3 = boto3.client(
|
||||
's3',
|
||||
endpoint_url=STORAGE_ENDPOINT,
|
||||
aws_access_key_id=STORAGE_ACCESS_KEY,
|
||||
aws_secret_access_key=STORAGE_SECRET_KEY
|
||||
)
|
||||
|
||||
s3.upload_fileobj(
|
||||
file_obj,
|
||||
STORAGE_BUCKET_NAME,
|
||||
file_name,
|
||||
ExtraArgs={'ACL': 'public-read'} # دسترسی عمومی
|
||||
)
|
||||
|
||||
return f"{STORAGE_ENDPOINT}/{STORAGE_ENDPOINT}/{file_name}"
|
||||
|
||||
except NoCredentialsError:
|
||||
raise Exception("اعتبارنامههای AWS معتبر نیستند")
|
||||
except Exception as e:
|
||||
raise Exception(f"خطا در آپلود فایل: {e}")
|
||||
|
||||
Reference in New Issue
Block a user