add bucket in CRD
All checks were successful
Build and Publish / build-release (push) Successful in 44s
All checks were successful
Build and Publish / build-release (push) Successful in 44s
This commit is contained in:
23
app/s3.py
23
app/s3.py
@@ -49,16 +49,25 @@ def ensure_bucket_exists() -> None:
|
||||
def upload_file(file: UploadFile, s3_key: str, content_type: str, metadata: dict = None) -> str:
|
||||
"""Upload file to S3 with metadata"""
|
||||
client = get_client()
|
||||
|
||||
|
||||
# Read file content
|
||||
file.file.seek(0, os.SEEK_END)
|
||||
file_size = file.file.tell()
|
||||
file.file.seek(0)
|
||||
file_content = file.file.read()
|
||||
file.file.seek(0)
|
||||
|
||||
extra_args = {"ContentType": content_type}
|
||||
if metadata:
|
||||
extra_args["Metadata"] = metadata
|
||||
|
||||
client.upload_fileobj(
|
||||
file.file,
|
||||
settings.s3_bucket,
|
||||
s3_key,
|
||||
ExtraArgs=extra_args
|
||||
|
||||
client.put_object(
|
||||
Bucket=settings.s3_bucket,
|
||||
Key=s3_key,
|
||||
Body=file_content,
|
||||
ContentLength=file_size,
|
||||
ContentType=content_type,
|
||||
Metadata=metadata
|
||||
)
|
||||
return s3_key
|
||||
|
||||
|
||||
Reference in New Issue
Block a user