Fix multipart file upload handling in HTTP client#516
Open
BinoyOza-okta wants to merge 2 commits intomasterfrom
Open
Fix multipart file upload handling in HTTP client#516BinoyOza-okta wants to merge 2 commits intomasterfrom
BinoyOza-okta wants to merge 2 commits intomasterfrom
Conversation
- Fix Content-Type header handling for multipart/form-data requests - Add proper file data handling for binary uploads in aiohttp - Remove Content-Type header to allow aiohttp to set boundary automatically - Update form parameter processing to handle both dict and list formats - Support new tuple-based file upload format: [(field_name, (filename, filedata, mimetype))] This fixes the multipart upload endpoints for theme images (logo, favicon, background) where the Content-Type boundary was being overridden, causing "no multipart boundary param" errors. Fixes: Theme image upload endpoints returning 400 errors Related files: - okta/http_client.py - okta/api/themes_api.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The theme image upload endpoints (
upload_brand_theme_logo,upload_brand_theme_favicon,upload_brand_theme_background_image) were failing with 400 errors due to incorrect multipart/form-data handling.Root Cause
Content-Type: multipart/form-dataheader without the requiredboundaryparameteraiohttp.FormData, the library needs to generate its own boundary and set the Content-Type headerSolution
Changes Made
HTTP Client (
okta/http_client.py):_remove_content_type_header()helper function to strip Content-Type when using FormDataaiohttp.FormDataby:API Layer (
okta/api/themes_api.py):Implementation Details
The fix handles two upload patterns:
Pattern 1 - New format (tuple-based):
Pattern 2 - Legacy format (dict with file path):
{"file": "/path/to/logo.png"}Testing
Tested with:
Example usage:
Verification
Breaking Changes
None - this fix is backward compatible with existing code.