uploads: Add a method to copy attachment contents out.

This commit is contained in:
Alex Vandiver
2023-03-14 16:16:41 +00:00
committed by Tim Abbott
parent 885334a3ad
commit e408f069fe
6 changed files with 46 additions and 6 deletions

View File

@@ -4,7 +4,7 @@ import secrets
import urllib
from datetime import datetime
from mimetypes import guess_type
from typing import IO, Any, Callable, Iterator, List, Optional, Tuple
from typing import IO, Any, BinaryIO, Callable, Iterator, List, Optional, Tuple
import boto3
import botocore
@@ -231,6 +231,10 @@ class S3UploadBackend(ZulipUploadBackend):
)
return url
def save_attachment_contents(self, path_id: str, filehandle: BinaryIO) -> None:
for chunk in self.uploads_bucket.Object(path_id).get()["Body"]:
filehandle.write(chunk)
def delete_message_attachment(self, path_id: str) -> bool:
return self.delete_file_from_s3(path_id, self.uploads_bucket)