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

Allow passing django file objects to sendfile #50

Closed
sevdog opened this issue Mar 25, 2021 · 3 comments
Closed

Allow passing django file objects to sendfile #50

sevdog opened this issue Mar 25, 2021 · 3 comments

Comments

@sevdog
Copy link

sevdog commented Mar 25, 2021

It would be great if sendfile could support django.core.files.File and django.db.models.fields.FileField as an argument in place of filename.

This could improve usability, since many files are stored as filefield.

@moggers87
Copy link
Owner

That would only work if FileSystemStorage was being used as FileField doesn't store the MIME type, so we'd to inspect the file ourselves. The user could pass in a MIME type themselves, but that defeats the point of supporting FileField in the first place 😸

@sevdog
Copy link
Author

sevdog commented Mar 25, 2021

I was not thinking about mime-type guessing, since that is not stored nor accessible via django file API.

I was thinking about a more user-friendly approach by using:

sendfile(mymodel.file_field)
sendfile(myfile)

In place of the current:

sendfile(mymodel.file_field.path)
sendfile(myfile.name)

Obviously to work with FileField (and derived fields) field.storage must implement the path method or whatever method is required by sendfile and an ImproperlyConfigured error should be raised otherwise.

@moggers87
Copy link
Owner

I'm liking this idea less and less. Users are going to be confused and frustrated if we tell them we support File and FileField directly, only to find out we only support one storage backend.

Thanks for submitting this issue, but I don't think we'll be implementing this.

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

No branches or pull requests

2 participants