Skip to content

Conversation

@fedexman
Copy link

Fix media type inference for URLs with query parameters

When using presigned URLs (eg AWS S3) with ImageUrl, AudioUrl, or VideoUrl, the media type inference fails

https://pics.s3.ap-northeast-1.amazonaws.com/test/Capture-2025-11-21-112402.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=fdafdas%2F20251121%2Fap-northeast-1%2Fs3%2Faws4_request&X-Amz-Date=20251121T023200Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEDoaD

to the agent we get this error,

Internal server error: Could not infer media type from image URL: 
...
Explicitly provide a `media_type` instead

the reason is that the _infer_media_type function only check the end of the url with url.endswith('.mkv') but do not parse the url.

I propose to parse the url with

from urllib.parse import urlparse
path = urlparse(self.url).path
if path.endswith('.mkv'):
            return 'video/x-matroska'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant