From 67c2836668070e1953ddceeff5a6f32562df734a Mon Sep 17 00:00:00 2001 From: jowilf Date: Tue, 30 Aug 2022 20:20:34 +0100 Subject: [PATCH] Add `upload_storage` to the default information saved into the database. Before, upload_storage can be extracted from `path` attribute. Now you can access directly with file['upload_storage']. --- .gitignore | 4 +++- pyproject.toml | 1 + sqlalchemy_file/file.py | 4 +++- sqlalchemy_file/processors.py | 18 ++++++++++-------- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index aac1aae..ec8b556 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ htmlcov coverage.xml site *.db -.cache \ No newline at end of file +.cache +__pycache__/ +.pytest_cache/ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 6f1ac2c..14c8682 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ license = "MIT" readme = "README.md" homepage = "https://jowilf.github.io/sqlalchemy-file" repository = "https://github.com/jowilf/sqlalchemy-file" +keywords = ["sqlalchemy", "sqlmodel", "file-upload", "apache-libcloud"] classifiers = [ 'Development Status :: 4 - Beta', "Framework :: AsyncIO", diff --git a/sqlalchemy_file/file.py b/sqlalchemy_file/file.py index c15eb9c..5d0402c 100644 --- a/sqlalchemy_file/file.py +++ b/sqlalchemy_file/file.py @@ -27,7 +27,8 @@ class File(BaseFile): filename (str): This is the name of the uploaded file file_id: This is the generated UUID for the uploaded file - path: This is a compination of `upload_storage` and `file_id` separated by + upload_storage: Name of the storage used to save the uploaded file + path: This is a combination of `upload_storage` and `file_id` separated by `/`. This will be use later to retrieve the file content_type: This is the content type of the uploaded file uploaded_at (datetime): This is the upload date in ISO format @@ -88,6 +89,7 @@ def save_to_storage(self, upload_storage: Optional[str] = None) -> None: metadata={"filename": self.filename, "content_type": self.content_type}, ) self["file_id"] = stored_file.name + self["upload_storage"] = upload_storage self["uploaded_at"] = datetime.utcnow().isoformat() self["path"] = "%s/%s" % (upload_storage, stored_file.name) self["url"] = stored_file.get_cdn_url() diff --git a/sqlalchemy_file/processors.py b/sqlalchemy_file/processors.py index 9f880c9..8556eb2 100644 --- a/sqlalchemy_file/processors.py +++ b/sqlalchemy_file/processors.py @@ -47,14 +47,15 @@ class ThumbnailGenerator(Processor): Properties available in `thumbnail` attribute - - **file_id:** This is the ID of the uploaded thumbnail file - - **path:** This is a upload_storage/file_id path which can - be used with :meth:`StorageManager.get_file` to - retrieve the thumbnail file - - **width** This is the width of the thumbnail image - - **height:** This is the height of the thumbnail image - - **url:** Public url of the uploaded file provided - by libcloud method `Object.get_cdn_url()` + - **file_id:** This is the ID of the uploaded thumbnail file + - **upload_storage:** Name of the storage used to save the uploaded file + - **path:** This is a upload_storage/file_id path which can + be used with :meth:`StorageManager.get_file` to + retrieve the thumbnail file + - **width** This is the width of the thumbnail image + - **height:** This is the height of the thumbnail image + - **url:** Public url of the uploaded file provided + by libcloud method `Object.get_cdn_url()` Example: ```Python @@ -129,6 +130,7 @@ def process(self, file: "File", upload_storage: Optional[str] = None) -> None: "file_id": stored_file.name, "width": width, "height": height, + "upload_storage": upload_storage, "path": "%s/%s" % (upload_storage, stored_file.name), "url": stored_file.get_cdn_url(), }