Skip to content

Commit 67c2836

Browse files
committed
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'].
1 parent c51bc3a commit 67c2836

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ htmlcov
1111
coverage.xml
1212
site
1313
*.db
14-
.cache
14+
.cache
15+
__pycache__/
16+
.pytest_cache/

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = "MIT"
77
readme = "README.md"
88
homepage = "https://jowilf.github.io/sqlalchemy-file"
99
repository = "https://github.com/jowilf/sqlalchemy-file"
10+
keywords = ["sqlalchemy", "sqlmodel", "file-upload", "apache-libcloud"]
1011
classifiers = [
1112
'Development Status :: 4 - Beta',
1213
"Framework :: AsyncIO",

sqlalchemy_file/file.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class File(BaseFile):
2727
2828
filename (str): This is the name of the uploaded file
2929
file_id: This is the generated UUID for the uploaded file
30-
path: This is a compination of `upload_storage` and `file_id` separated by
30+
upload_storage: Name of the storage used to save the uploaded file
31+
path: This is a combination of `upload_storage` and `file_id` separated by
3132
`/`. This will be use later to retrieve the file
3233
content_type: This is the content type of the uploaded file
3334
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:
8889
metadata={"filename": self.filename, "content_type": self.content_type},
8990
)
9091
self["file_id"] = stored_file.name
92+
self["upload_storage"] = upload_storage
9193
self["uploaded_at"] = datetime.utcnow().isoformat()
9294
self["path"] = "%s/%s" % (upload_storage, stored_file.name)
9395
self["url"] = stored_file.get_cdn_url()

sqlalchemy_file/processors.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ class ThumbnailGenerator(Processor):
4747
4848
Properties available in `thumbnail` attribute
4949
50-
- **file_id:** This is the ID of the uploaded thumbnail file
51-
- **path:** This is a upload_storage/file_id path which can
52-
be used with :meth:`StorageManager.get_file` to
53-
retrieve the thumbnail file
54-
- **width** This is the width of the thumbnail image
55-
- **height:** This is the height of the thumbnail image
56-
- **url:** Public url of the uploaded file provided
57-
by libcloud method `Object.get_cdn_url()`
50+
- **file_id:** This is the ID of the uploaded thumbnail file
51+
- **upload_storage:** Name of the storage used to save the uploaded file
52+
- **path:** This is a upload_storage/file_id path which can
53+
be used with :meth:`StorageManager.get_file` to
54+
retrieve the thumbnail file
55+
- **width** This is the width of the thumbnail image
56+
- **height:** This is the height of the thumbnail image
57+
- **url:** Public url of the uploaded file provided
58+
by libcloud method `Object.get_cdn_url()`
5859
5960
Example:
6061
```Python
@@ -129,6 +130,7 @@ def process(self, file: "File", upload_storage: Optional[str] = None) -> None:
129130
"file_id": stored_file.name,
130131
"width": width,
131132
"height": height,
133+
"upload_storage": upload_storage,
132134
"path": "%s/%s" % (upload_storage, stored_file.name),
133135
"url": stored_file.get_cdn_url(),
134136
}

0 commit comments

Comments
 (0)