Skip to content

Commit

Permalink
Add upload_storage to the default information saved into the databa…
Browse files Browse the repository at this point in the history
…se. Before, upload_storage can be extracted from `path` attribute. Now you can access directly with file['upload_storage'].
  • Loading branch information
jowilf committed Aug 30, 2022
1 parent c51bc3a commit 67c2836
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ htmlcov
coverage.xml
site
*.db
.cache
.cache
__pycache__/
.pytest_cache/
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion sqlalchemy_file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 10 additions & 8 deletions sqlalchemy_file/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
}
Expand Down

0 comments on commit 67c2836

Please sign in to comment.