Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced naming filename for FileSystemStorage #49

Merged
merged 2 commits into from
Apr 26, 2024

Conversation

hannal
Copy link
Contributor

@hannal hannal commented Apr 26, 2024

Hi,

The write method of FileSystemStorage creates the path directly, which I think is the same behavior as the get_name and get_path methods. How about using the get_name and get_path methods? This is because this way we can override these two methods to have more control over the file storage path.

Here's an example.

class FileSystemStorage(BaseFileSystemStorage):
    _path_factory: Optional[Callable] = None

    def __init__(self, path: Optional[Path | str] = None, path_factory: Optional[Callable] = None) -> None:
        self._path_factory = path_factory
        super().__init__(path)

    def get_path(self, name: str) -> str:
        if callable(self._path_factory):
            _path = self._path_factory()
        else:
            _path = self._path

        return str(Path(_path) / Path(name))

Copy link
Owner

@aminalaee aminalaee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR 👍

@aminalaee aminalaee merged commit 0ff4218 into aminalaee:main Apr 26, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants