Opened 9 years ago

Closed 9 years ago

#26106 closed Cleanup/optimization (invalid)

Inconsistency on uploaded image format name

Reported by: Benjamin Owned by: nobody
Component: Uncategorized Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

on my code I intercept form data posted both from the admin and template frontend.
I need to catch the format name and use it in my code.

From the frontend, to get to this value from a submitted form request.FILES the path is:
image.image.format

From the admin, when submitting a new image in a field, saving, then intercepting the file with a save signal, from the instance, the path to the image format is:
image.file.image.format

I'm not sure this is intended.... anyway it can cause problem.

Change History (4)

comment:1 by Tim Graham, 9 years ago

Resolution: needsinfo
Status: newclosed

I'm not sure how to reproduce the issue. In particular, where does the "format" attribute come from? I don't think it's part of Django. Is it possible this is related to a third-party library and not Django itself? If not, please include some more specific steps to reproduce the problem (models, view code, etc.) and reopen the ticket. Thank you.

comment:2 by Benjamin, 9 years ago

Resolution: needsinfo
Status: closednew

Create a simple form on a template with an image field.
Submit form but don't save it, use commit=false.

Then inspect the 'request/FILES/0/image/format '
I believe this is part of Django isn't it ?
This format parameter also appear in other place of the request, such as in 'request/_files/0/image/format'

So it seems the format that is passed when submitting form from frontend template, and admin, doesn't use same path.
It's really minor issue, but for the sake of consistency, if it's related to django, it might deserve to get fixed.

comment:3 by Tim Graham, 9 years ago

Here's what I see in request.FILES when uploading with the admin:

>>> request.FILES['image']
<TemporaryUploadedFile: IMG_1856.JPG (image/jpeg)>
>>> request.FILES['image'].image
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=3072x2304 at 0x7FB23C047240>
>>> request.FILES['image'].image.format
'JPEG'

It's still not clear to me how to reproduce the problem in the report (or what the problem is). If you could use actual code instead of psuedocode, that would help clarify.

comment:4 by Tim Graham, 9 years ago

Resolution: invalid
Status: newclosed

I guess the other case you mentioned might be:

>>> new_object = form.save(commit=False)
<ImageModel: ImageModel object>
>>> new_object.image
<ImageFieldFile: IMG_1857.JPG>
>>> new_object.image.file
<TemporaryUploadedFile: IMG_1857.JPG (image/jpeg)>
>>> new_object.image.file.image
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=3072x2304 at 0x7F2A9FD24128>
>>> new_object.image.file.image.format
'JPEG'

I don't see an inconsistency given these are two separate circumstances.

Note: See TracTickets for help on using tickets.
Back to Top