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

Remove requirement for image dimensions in API #17070

Closed
llamafilm opened this issue Aug 2, 2024 · 2 comments · Fixed by #17234
Closed

Remove requirement for image dimensions in API #17070

llamafilm opened this issue Aug 2, 2024 · 2 comments · Fixed by #17234
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@llamafilm
Copy link
Contributor

llamafilm commented Aug 2, 2024

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

@llamafilm llamafilm added status: needs triage This issue is awaiting triage by a maintainer type: feature Introduction of new functionality to the application labels Aug 2, 2024
@DanSheps DanSheps added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation complexity: low Requires minimal effort to implement and removed status: needs triage This issue is awaiting triage by a maintainer labels Aug 2, 2024
@DanSheps DanSheps removed their assignment Aug 2, 2024
@llamafilm
Copy link
Contributor Author

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()

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Aug 21, 2024
@jeremystretch
Copy link
Member

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

@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application severity: low Does not significantly disrupt application functionality, or a workaround is available and removed type: feature Introduction of new functionality to the application complexity: low Requires minimal effort to implement labels Aug 22, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
4 participants