SVG image upload fail for rear/front image in device types #4341

Closed
opened 2025-12-29 18:34:57 +01:00 by adam · 3 comments
Owner

Originally created by @netixx on GitHub (Dec 9, 2020).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.8.6
  • NetBox version: 2.9.9

Steps to Reproduce

  1. Edit a device type
  2. Select an SVG file as a rear or front
  3. Save the form

Expected Behavior

Image is uploaded and save with the device type

Observed Behavior

Error returned on the image field :
Upload a valid image. The file you uploaded was either not an image or a corrupted image.

We are using the file storage backend. We also tried SVGZ format which didn't work as well.
PNG upload works fine.

Originally created by @netixx on GitHub (Dec 9, 2020). Originally assigned to: @jeremystretch on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/g/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 3.8.6 * NetBox version: 2.9.9 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. Edit a device type 2. Select an SVG file as a rear or front 3. Save the form <!-- What did you expect to happen? --> ### Expected Behavior Image is uploaded and save with the device type <!-- What happened instead? --> ### Observed Behavior Error returned on the image field : `Upload a valid image. The file you uploaded was either not an image or a corrupted image.` We are using the file storage backend. We also tried SVGZ format which didn't work as well. PNG upload works fine.
adam added the type: bugstatus: accepted labels 2025-12-29 18:34:57 +01:00
adam closed this issue 2025-12-29 18:34:57 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 9, 2020):

This is due to lack of support for SVG in the PIL library, which is used by Django's ImageField for validation (see Django bug #14092).

Changing the front_image and rear_image fields on the DeviceType model to FileFields would allow for SVG upload, however custom validation would be needed to ensure uploaded files are valid images.

@jeremystretch commented on GitHub (Dec 9, 2020): This is due to lack of support for SVG in the PIL library, which is used by Django's ImageField for validation (see [Django bug #14092](https://code.djangoproject.com/ticket/14092)). Changing the `front_image` and `rear_image` fields on the DeviceType model to FileFields would allow for SVG upload, however custom validation would be needed to ensure uploaded files are valid images.
Author
Owner

@netixx commented on GitHub (Dec 9, 2020):

Thank you for the update. In the meantime, could we restrict the image types in the image picker/system browser to supported types only ?

In my case, I was mislead because I saw "*.svg, *.svgz" in the filtered file types.

@netixx commented on GitHub (Dec 9, 2020): Thank you for the update. In the meantime, could we restrict the image types in the image picker/system browser to supported types only ? In my case, I was mislead because I saw "*.svg, *.svgz" in the filtered file types.
Author
Owner

@jeremystretch commented on GitHub (Dec 11, 2020):

In the meantime, could we restrict the image types in the image picker/system browser to supported types only ?

Yes, I think that makes sense. I'm going to limit the accepted file types to exclude SVG. Still happy to entertain moving away from ImageField to ultimately enable support for SVG, but as mentioned that will be more involved so it would need a separate FR.

@jeremystretch commented on GitHub (Dec 11, 2020): > In the meantime, could we restrict the image types in the image picker/system browser to supported types only ? Yes, I think that makes sense. I'm going to limit the accepted file types to exclude SVG. Still happy to entertain moving away from ImageField to ultimately enable support for SVG, but as mentioned that will be more involved so it would need a separate FR.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4341