-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fixes: #19669 - Add an API endpoint to download image attachments #19950
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
Conversation
netbox/extras/api/views.py
Outdated
def download(self, request, pk, *args, **kwargs): | ||
obj = get_object_or_404(self.queryset, pk=pk) | ||
# Render and return the elevation as an SVG drawing with the correct content type | ||
return serve(request, obj.image.path, document_root=settings.MEDIA_ROOT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this path construction correct? When I run this I get:
GET /api/extras/image-attachments/1/download/
HTTP 404 Not Found
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"detail": "“/Users/btman/Development/netbox-community/netbox/netbox/media/Users/btman/Development/netbox-community/netbox/netbox/media/image-attachments/device_27_20240730_212632-51361-scaled.jpg” does not exist"
}
My MEDIA_ROOT
is /Users/btman/Development/netbox-community/netbox/netbox/media
It works if I set document_root="/"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Odd, it did work when I tested it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to try and construct a test for this as well. Just need to figure out the best way to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See inline comment.
We should also consider FR #18396, which concerns front & rear images for device types. The proposed new endpoint serves image attachments, but not image fields in general. What should we do for other images? A consistent approach would be preferable. |
Per discussion in maintainers meeting, we will be allowing Token Authentication against the /media/* URL |
Fixes: #19669 - Add an API endpoint to download image attachments