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

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

Closed
christianpinger opened this issue Jun 28, 2017 · 7 comments · Fixed by #1315
Closed

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

christianpinger opened this issue Jun 28, 2017 · 7 comments · Fixed by #1315

Comments

@christianpinger
Copy link
Contributor

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.

@jeremystretch
Copy link
Member

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?

@christianpinger
Copy link
Contributor Author

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.

@jeremystretch
Copy link
Member

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

@christianpinger
Copy link
Contributor Author

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

@jeremystretch
Copy link
Member

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.

@christianpinger
Copy link
Contributor Author

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:

@jeremystretch
Copy link
Member

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

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants