To reproduce:
- Create a model {{{image1 = models.ImageField(upload_to=lambda instance,
filename: 'image1/{}'.format(instance.pk), blank=True)}}}. Make sure that
upload_to does not contains any extension
- Create an instance of that model in Django Admin with a file uploaded.
- Try to update the just created model with no changes. It will fail with
the error "File extension '' is not allowed. Allowed extensions are: 'bmp,
bufr, cur, pcx, dcx, dds, ps, eps, fit, fits, fli, flc, fpx, ftc, ftu,
gbr, gif, grib, h5, hdf, png, jp2, j2k, jpc, jpf, jpx, j2c, icns, ico, im,
iim, tif, tiff, jfif, jpe, jpg, jpeg, mic, mpg, mpeg, mpo, msp, palm, pcd,
pdf, pxr, pbm, pgm, ppm, psd, bw, rgb, rgba, sgi, ras, tga, webp, wmf,
emf, xbm, xpm'." on the field.
This issue is not present in 1.10.7 (as #21548 is not merged yet).
--
Ticket URL: <https://code.djangoproject.com/ticket/28242>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Manatsawin Hanmongkolchai):
I've ran bisect already and confirmed that
12b4280444b58c94197255655e284e4103fe00a9 is the first bad commit. (I
haven't wrote an automated test, instead wrote a test Django project and
manually tested)
--
Ticket URL: <https://code.djangoproject.com/ticket/28242#comment:1>
Comment (by Tim Graham):
Can you elaborate on your use case for saving images without extensions?
I'm not sure if this is a common enough use case to justify some change in
Django. You could subclass the `ImageField` model field and set
`default_validators = []` if you don't want the extension validator.
--
Ticket URL: <https://code.djangoproject.com/ticket/28242#comment:2>
Comment (by Manatsawin Hanmongkolchai):
In my use case, user would upload images that are saved to Amazon S3
(using django-storages). As the image is one per user (eg. avatar), naming
the image by their user ID seems to make sense that it make other
applications in my system able to find the image easily.
As we're already on S3, I felt it is not neccessary to add an extension to
the file name (as S3 would already have the Content-Type metadata, which
django-storages would set automatically from the original extension). It
also make the upload_to function easier to implement.
--
Ticket URL: <https://code.djangoproject.com/ticket/28242#comment:3>
Comment (by Tim Graham):
Could you offer a patch that would reallow your use case?
--
Ticket URL: <https://code.djangoproject.com/ticket/28242#comment:4>
Comment (by Manatsawin Hanmongkolchai):
I'd be willing to work on getting this resolved.
I poked a bit around the codebase earlier, and I think that the my
solution to this would be to change the validator to skip empty files.
However, empty files seems to be a valid upload as well (#13584) so I
might need another way to detect that the browser submitted an empty
<input type="file">.
I haven't get the full grasp of this issue yet as it involving several
related components. If you have any suggestion I'd be appreciated.
--
Ticket URL: <https://code.djangoproject.com/ticket/28242#comment:5>
* has_patch: 0 => 1
Comment:
I've submitted a pull request: https://github.com/django/django/pull/8565
--
Ticket URL: <https://code.djangoproject.com/ticket/28242#comment:6>
* type: Bug => Cleanup/optimization
* component: File uploads/storage => Forms
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28242#comment:7>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"a0c07d77fc313388c72a17cd59411265069f037f" a0c07d77]:
{{{
#!CommitTicketReference repository=""
revision="a0c07d77fc313388c72a17cd59411265069f037f"
Fixed #28242 -- Moved ImageField file extension validation to the form
field.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28242#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"110bd820380e06fc8572f94b36bba6fc9d057a6b" 110bd82]:
{{{
#!CommitTicketReference repository=""
revision="110bd820380e06fc8572f94b36bba6fc9d057a6b"
[1.11.x] Fixed #28242 -- Moved ImageField file extension validation to the
form field.
Backport of a0c07d77fc313388c72a17cd59411265069f037f from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28242#comment:9>