fix: resolve GCS bad request error in media uploads. #1265
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
This PR addresses the issue reported in langfuse/langfuse#7517 where media file uploads to Google Cloud Storage (GCS) were failing with the following Bad Request error:
This error occurred because GCS doesn't recognize AWS S3-specific headers like
x-amz-checksum-sha256
and Azure Blob Storage headers likex-ms-blob-type
that were being sent to all providers.Solution
Modified the upload logic to conditionally set headers based on the cloud storage provider:
storage.googleapis.com
): Only sendContent-Type
headerContent-Type
,x-ms-blob-type
, andx-amz-checksum-sha256
headersChanges
_process_upload_media_job
method to conditionally set headers based on upload URLstorage.googleapis.com
in upload URL to skip problematic headers for GCSTest Results Summary
test_init_with_base64_data_uri
test_init_with_content_bytes
test_init_with_invalid_input
test_content_length
test_content_sha256_hash
test_reference_string
test_parse_reference_string
test_parse_invalid_reference_string
test_file_handling
test_nonexistent_file
test_replace_media_reference_string_in_object
Related Issues
Fixes langfuse/langfuse#7517