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

Usage as a non-default media storage engine #110

Open
jayvdb opened this issue Aug 25, 2020 · 0 comments
Open

Usage as a non-default media storage engine #110

jayvdb opened this issue Aug 25, 2020 · 0 comments
Assignees

Comments

@jayvdb
Copy link

jayvdb commented Aug 25, 2020

After quite a bit of mucking around, I was able to get this working without putting DEFAULT_FILE_STORAGE = 'db_file_storage.storage.DatabaseFileStorage' in my settings as is described in the README.

I wrote up my use case in a bit more detail at kimetrica/django-binary-database-files#31 which I was also experimenting with.

I found how to get it working with the use of storage=DatabaseStorage(..) in their tests, and notice there isn't any similar tests or docs here which explain how to do that. See also kimetrica/django-binary-database-files#32 about that. I had seen storage was available in the core Django field docs , but I tried quite a few incorrect incantations before realising how simple it was.

The models setup I have used is

from db_file_storage.storage import DatabaseFileStorage


class Filestore(models.Model):
    data = models.BinaryField()
    filename = models.CharField(max_length=255)
    mimetype = models.CharField(max_length=50)


class Image(models.Model):
    name = models.CharField(max_length=100)
    image = models.ImageField(
        storage=DatabaseFileStorage(),
        upload_to='app.Filestore/data/filename/mimetype',
        blank=True, null=True)

I think this should be explained in the docs, and have tests to make sure it works correctly without relying on DEFAULT_FILE_STORAGE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants