diff --git a/other/transfer_images_minio_subfolder.py b/other/transfer_images_minio_subfolder.py index c531892..cb5305e 100644 --- a/other/transfer_images_minio_subfolder.py +++ b/other/transfer_images_minio_subfolder.py @@ -27,6 +27,7 @@ if __name__ == '__main__': # get image from minio buffer = get( client=minio_client, + bucket_name=BUCKET_NAME, object_name=obj.object_name, ) # convert data to image diff --git a/other/transfer_images_mongo_minio.py b/other/transfer_images_mongo_minio.py index b8d38c9..7e8f5cc 100644 --- a/other/transfer_images_mongo_minio.py +++ b/other/transfer_images_mongo_minio.py @@ -3,16 +3,15 @@ from __future__ import annotations import logging -from io import BytesIO from pathlib import Path from bson import ObjectId from dotenv import load_dotenv from pymongo.collection import Collection -from shared.datastore import connect_minio, put +from shared.datastore import connect_minio, put_image from shared.mongodb import connect_mongodb -from shared.mongodb.classes import VisualCommunication +from shared.mongodb.src.classes import VisualCommunication from shared.utils import check_env, setup_logging from web_ui.src.main import NECESSARY_ENV_VAR_LIST @@ -96,13 +95,14 @@ if __name__ == '__main__': logging.error('failed getting image from document: %s', doc_id) continue try: - # save image to buffer - buffer = BytesIO() - vis_com.image.save(buffer, 'png') # type: ignore + # get image + image = vis_com.get_image( + minio_client=minio_client, + ) # put buffer in minio - object_name = put( + object_name = put_image( client=minio_client, - buffer=buffer, + image=image, ) except Exception as exc: logging.debug(exc) diff --git a/shared/mongodb/src/classes/visual_communication.py b/shared/mongodb/src/classes/visual_communication.py index 9c0383f..a21d0b4 100755 --- a/shared/mongodb/src/classes/visual_communication.py +++ b/shared/mongodb/src/classes/visual_communication.py @@ -12,8 +12,8 @@ from PIL import Image from pydantic import BaseModel, ConfigDict from pymongo.collection import Collection -from shared.datastore import get, put -from shared.mongodb.classes import ModelData +from shared.datastore import get_image, put_image +from shared.mongodb.src.classes import ModelData class VisualCommunication(BaseModel): @@ -39,11 +39,9 @@ class VisualCommunication(BaseModel): """Upload image to MinIO and return MD5 checksum of hashed image.""" assert isinstance(image, Image.Image) assert isinstance(minio_client, Minio) - buffer = BytesIO() - image.save(buffer, 'png') - object_name = put( + object_name = put_image( client=minio_client, - buffer=buffer, + image=image, ) return object_name @@ -92,14 +90,12 @@ class VisualCommunication(BaseModel): def get_image(self, minio_client: Minio) -> Image.Image: """Load image data from minio.""" assert isinstance(minio_client, Minio) - # get buffer from minio - buffer = get( + # get image from minio + image = get_image( client=minio_client, object_name=self.object_name, ) - # convert data to image - im = Image.open(buffer) - return im + return image def save_to_mongo(self, collection: Collection) -> None: """Save self as document in MongoDB.""" diff --git a/web_ui/src/app/init_app.py b/web_ui/src/app/init_app.py index 1187e73..897aa69 100644 --- a/web_ui/src/app/init_app.py +++ b/web_ui/src/app/init_app.py @@ -14,8 +14,8 @@ from pymongo.collection import Collection from shared.datastore import delete as delete_from_minio from shared.mongodb import count_documents, get_visual_communication, upsert_annotation -from shared.mongodb.classes import ModelData, VisualCommunication -from shared.mongodb.exceptions import NoDocumentFoundException +from shared.mongodb.src.classes import ModelData, VisualCommunication +from shared.mongodb.src.exceptions import NoDocumentFoundException from .layout import app_layout @@ -146,8 +146,10 @@ def init_app( logging.debug(exc) failed_filename_list.append(filename) # remove document from minio + bucket_name = os.getenv('MINIO_BUCKET_NAME', default='') delete_from_minio( client=minio_client, + bucket_name=bucket_name, object_name=vis_com.object_name, ) assert (