Remove requirement for image dimensions in API #10043

Closed
opened 2025-12-29 21:26:07 +01:00 by adam · 2 comments
Owner

Originally created by @llamafilm on GitHub (Aug 2, 2024).

Originally assigned to: @bctiemann on GitHub.

NetBox version

v4.0.8

Feature type

Change to existing functionality

Proposed functionality

When uploading an image attachment via API, it should not require image_height and image_width fields. These should be calculated automatically, as they are when uploading using the GUI. Actually this already works, if you provide incorrect values (any integer) they will be ignored, and Netbox figures out the correct dimensions.

As an example, I'd like to use code like this:

files = { 'image': open(filename, 'rb') }
payload = {
    'name': filename,
    'object_id': 454,
    'object_type': 'dcim.site'
}
url = f'{base_url}/api/extras/image-attachments/'
req = requests.post(url, headers=headers, files=files, data=payload)

This currently fails with 400: {"image_height":["This field is required."],"image_width":["This field is required."]}

Use case

Calculating image dimensions requires extra work, and Netbox is already capable of doing this automatically, as it does when you upload using the GUI.

Database changes

none

External dependencies

No response

Originally created by @llamafilm on GitHub (Aug 2, 2024). Originally assigned to: @bctiemann on GitHub. ### NetBox version v4.0.8 ### Feature type Change to existing functionality ### Proposed functionality When uploading an image attachment via API, it should not require `image_height` and `image_width` fields. These should be calculated automatically, as they are when uploading using the GUI. Actually this already works, if you provide incorrect values (any integer) they will be ignored, and Netbox figures out the correct dimensions. As an example, I'd like to use code like this: ```py files = { 'image': open(filename, 'rb') } payload = { 'name': filename, 'object_id': 454, 'object_type': 'dcim.site' } url = f'{base_url}/api/extras/image-attachments/' req = requests.post(url, headers=headers, files=files, data=payload) ``` This currently fails with 400: `{"image_height":["This field is required."],"image_width":["This field is required."]}` ### Use case Calculating image dimensions requires extra work, and Netbox is already capable of doing this automatically, as it does when you upload using the GUI. ### Database changes none ### External dependencies _No response_
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:26:07 +01:00
adam closed this issue 2025-12-29 21:26:07 +01:00
Author
Owner

@llamafilm commented on GitHub (Aug 2, 2024):

By the way, the same operation can be done in python without specifying dimensions:

from django.contrib.contenttypes.models import ContentType
from django.core.files.base import File
i = ImageAttachment(
    object_type=ContentType.objects.get(app_label='dcim', model='location'),
    object_id=14588,
    image=File(open('/tmp/image.png', 'rb')),
    name='my file'
)
i.full_clean()
i.save()
@llamafilm commented on GitHub (Aug 2, 2024): By the way, the same operation can be done in python without specifying dimensions: ```py from django.contrib.contenttypes.models import ContentType from django.core.files.base import File i = ImageAttachment( object_type=ContentType.objects.get(app_label='dcim', model='location'), object_id=14588, image=File(open('/tmp/image.png', 'rb')), name='my file' ) i.full_clean() i.save() ```
Author
Owner

@jeremystretch commented on GitHub (Aug 22, 2024):

Reclassifying this as a bug, as those fields should not be required.

@jeremystretch commented on GitHub (Aug 22, 2024): Reclassifying this as a bug, as those fields should not be required.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10043