Image is not displayed but downloaded, if name field is used #1062

Closed
opened 2025-12-29 16:28:25 +01:00 by adam · 7 comments
Owner

Originally created by @christianpinger on GitHub (Jun 28, 2017).

Issue type: bug

Python version: 2.7.6
NetBox version: 2.0.7

If an image is uploaded to a rack and a name like Back01 is entered, the image is downloaded with filename Back01 (no file extension). If the name field left empty, the image is displayed in a new tab, which is my preferred method to view the images.

Originally created by @christianpinger on GitHub (Jun 28, 2017). ### Issue type: bug **Python version:** 2.7.6 **NetBox version:** 2.0.7 If an image is uploaded to a rack and a name like Back01 is entered, the image is downloaded with filename Back01 (no file extension). If the name field left empty, the image is displayed in a new tab, which is my preferred method to view the images.
adam closed this issue 2025-12-29 16:28:25 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jun 28, 2017):

Providing a name merely renames the file during upload. It should not have any effect on retrieving the file. Could you please post a detailed list of steps necessary to recreate the problem, including the HTTP response sent in both cases?

@jeremystretch commented on GitHub (Jun 28, 2017): Providing a name merely renames the file during upload. It should not have any effect on retrieving the file. Could you please post a detailed list of steps necessary to recreate the problem, including the HTTP response sent in both cases?
Author
Owner

@christianpinger commented on GitHub (Jun 29, 2017):

I've noticed, it depends on the client who is uploading the image. I'll investigate and give feedback as soon as I have more details.

@christianpinger commented on GitHub (Jun 29, 2017): I've noticed, it depends on the client who is uploading the image. I'll investigate and give feedback as soon as I have more details.
Author
Owner

@jeremystretch commented on GitHub (Jun 29, 2017):

Maybe it has something to do with the MIME type. Could you experiment with different image types (e.g. JPG, PNG, BMP, etc.)?

@jeremystretch commented on GitHub (Jun 29, 2017): Maybe it has something to do with the MIME type. Could you experiment with different image types (e.g. JPG, PNG, BMP, etc.)?
Author
Owner

@christianpinger commented on GitHub (Jun 30, 2017):

If the file extension is in capslock, clicking on the file will download it and the extension is stripped away.

IMG1234.JPG will be site_5_foo and will get downloaded
IMG1234.jpg will be site_5_foo.jpg and displayed in a new tab

@christianpinger commented on GitHub (Jun 30, 2017): If the file extension is in capslock, clicking on the file will download it and the extension is stripped away. IMG1234.JPG will be site_5_foo and will get downloaded IMG1234.jpg will be site_5_foo.jpg and displayed in a new tab
Author
Owner

@jeremystretch commented on GitHub (Jun 30, 2017):

Sounds like something pertaining to your httpd configuration. In a production setup, media files are served by the web service (e.g. nginx or Apache) directly; NetBox has no control over how they are delivered to the client.

I'm going to close this out as it doesn't seem like something handled by the NetBox code base, but please feel free to pursue assistance on our mailing list.

@jeremystretch commented on GitHub (Jun 30, 2017): Sounds like something pertaining to your httpd configuration. In a production setup, media files are served by the web service (e.g. nginx or Apache) directly; NetBox has no control over how they are delivered to the client. I'm going to close this out as it doesn't seem like something handled by the NetBox code base, but please feel free to pursue assistance on our [mailing list](https://groups.google.com/forum/#!forum/netbox-discuss).
Author
Owner

@christianpinger commented on GitHub (Jul 3, 2017):

You could at least implement case insensitive behaviour for fileextensions, which is cleaner in my opinion:

diff --git a/netbox/extras/models.py b/netbox/extras/models.py
index ade251c..3388f99 100644
--- a/netbox/extras/models.py
+++ b/netbox/extras/models.py
@@ -387,7 +387,7 @@ def image_upload(instance, filename):
     path = 'image-attachments/'

     # Rename the file to the provided name, if any. Attempt to preserve the file extension.
-    extension = filename.rsplit('.')[-1]
+    extension = filename.rsplit('.')[-1].lower()
     if instance.name and extension in ['bmp', 'gif', 'jpeg', 'jpg', 'png']:
         filename = '.'.join([instance.name, extension])
     elif instance.name:
@christianpinger commented on GitHub (Jul 3, 2017): You could at least implement case insensitive behaviour for fileextensions, which is cleaner in my opinion: ``` diff --git a/netbox/extras/models.py b/netbox/extras/models.py index ade251c..3388f99 100644 --- a/netbox/extras/models.py +++ b/netbox/extras/models.py @@ -387,7 +387,7 @@ def image_upload(instance, filename): path = 'image-attachments/' # Rename the file to the provided name, if any. Attempt to preserve the file extension. - extension = filename.rsplit('.')[-1] + extension = filename.rsplit('.')[-1].lower() if instance.name and extension in ['bmp', 'gif', 'jpeg', 'jpg', 'png']: filename = '.'.join([instance.name, extension]) elif instance.name: ```
Author
Owner

@jeremystretch commented on GitHub (Jul 3, 2017):

You're welcome to submit the above as a pull request.

@jeremystretch commented on GitHub (Jul 3, 2017): You're welcome to submit the above as a pull request.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1062