Skip to content

DatabaseStorage.path fail for files in the database but not on localstorage #44

Open
@rhunwicks

Description

@rhunwicks

Currently DatabaseStorage.path is:

        localpath = self._path(self.get_instance_name(name))
        if not os.path.exists(localpath):
            raise NotImplementedError
        return localpath

I.e. if the file doesn't exist locally then it raises NotImplementedError.

However, it is possible that if there are multiple webservers in front of a single database, then the file may be in the database but not in the local storage. The existing _open includes:

                # Automatically write the file to the filesystem
                # if it's missing and exists in the database.
                # This happens if we're using multiple web servers connected
                # to a common database behind a load balancer.
                # One user might upload a file from one web server, and then
                # another might access if from another server.
                utils.write_file(name, f.content)

We should apply the same approach to path to automatically write the file to the local filesystem if it exists in the database but not locally.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions