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

'FieldFile' object has no attribute 'content_type' #4

Open
tylerecouture opened this issue Jan 6, 2018 · 6 comments
Open

'FieldFile' object has no attribute 'content_type' #4

tylerecouture opened this issue Jan 6, 2018 · 6 comments

Comments

@tylerecouture
Copy link

I'm getting this error when trying to use a SafeFileField

Any idea what the problem might be?

Here's the field declaration:

custom_stylesheet = SafeFileField(null=True, blank=True, upload_to=user_directory_path, allowed_extensions=('css',))

Here's the error:

Request Method: POST
http://127.0.0.1:8000/profiles/1/edit/
1.11.6
AttributeError
'FieldFile' object has no attribute 'content_type'
.../python3.4/site-packages/safe_filefield/validators.py in call, line 66

Stack trace ends with:

.../python3.4/site-packages/safe_filefield/validators.py in __call__
 66.                   ext in mimetypes.guess_all_extensions(file.content_type)

Local Vars

Variable Value
__ 'custom'
detected_content_type 'text/plain'
ext '.css'
file <FieldFile: custom.css>
self <safe_filefield.validators.FileContentTypeValidator object at 0x7f3d09c05630>
@mixkorshun
Copy link
Owner

I don't have any idea what it can be.

Can you provide code of form and view classes which reproduce the error?

@trixden
Copy link

trixden commented May 24, 2018

I have that error in Django 1.11.7.

avatar = SafeFileField(upload_to=get_file_path, blank=True, null=True, verbose_name='Аватар',
        allowed_extensions=('jpg', 'jpeg', 'png', 'gif'))

I take this error in Django admin interface

@trixden
Copy link

trixden commented May 24, 2018

Error is hided, when i set check_content_type=False

@dpenztech
Copy link

I see that nsurbay fixed this issue in a commit on May 25, 2018. I found the problem still exists in the version in pypi, came here to research, replaced validators.py with the one from this site, and the error is gone. Thanks for the fix nsurbay! mixkorshun, can you see that pypi gets updated?

@nathando
Copy link

But there is also no new release after that fix ?

@oguzhancelikarslan
Copy link

Error is hided, when i set check_content_type=False

you don't want to do that. if you set check_content_type=False you almost remove the most important security layer in this app. You should not depend on only file extension validation.

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

6 participants