Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Jay-flow
Copy link
Contributor

@Jay-flow Jay-flow commented Jul 21, 2025

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:

<?xml version='1.0' encoding='UTF-8'?>
<Error>
  <Code>MalformedSecurityHeader</Code>
  <Message>Invalid argument.</Message>
  <Details>Your request has a malformed header. Header must be signed.</Details>
  <ParameterName>x-amz-checksum-sha256</ParameterName>
</Error>

This error occurred because GCS doesn't recognize AWS S3-specific headers like x-amz-checksum-sha256 and Azure Blob Storage headers like x-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:

  • Google Cloud Storage (storage.googleapis.com): Only send Content-Type header
  • Other providers (AWS S3, Azure, etc.): Send Content-Type, x-ms-blob-type, and x-amz-checksum-sha256 headers

Changes

  • Modified _process_upload_media_job method to conditionally set headers based on upload URL
  • Added check for storage.googleapis.com in upload URL to skip problematic headers for GCS
  • Maintained backward compatibility for other cloud storage providers

Test Results Summary

Test Function Description Status
test_init_with_base64_data_uri Base64 data URI initialization ✅ Passed
test_init_with_content_bytes Byte data initialization ✅ Passed
test_init_with_invalid_input Invalid input handling ✅ Passed
test_content_length Content length calculation ✅ Passed
test_content_sha256_hash SHA256 hash generation ✅ Passed
test_reference_string Reference string generation ✅ Passed
test_parse_reference_string Valid reference parsing ✅ Passed
test_parse_invalid_reference_string Invalid reference parsing ✅ Passed
test_file_handling File path handling ✅ Passed
test_nonexistent_file Non-existent file handling ✅ Passed
test_replace_media_reference_string_in_object Reference replacement in objects ✅ Passed

Related Issues

Fixes langfuse/langfuse#7517

@CLAassistant
Copy link

CLAassistant commented Jul 21, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ hassiebp
❌ Jay-flow
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@hassiebp hassiebp self-assigned this Jul 21, 2025
@Jay-flow Jay-flow changed the title Resolve GCS Bad Request error in media uploads. fix: Resolve GCS Bad Request error in media uploads. Jul 22, 2025
@Jay-flow Jay-flow changed the title fix: Resolve GCS Bad Request error in media uploads. fix: resolve GCS bad request error in media uploads. Jul 22, 2025
Resolve GCS Bad Request error by setting appropriate headers
for each cloud storage provider (S3, Azure, GCS).
@Jay-flow Jay-flow force-pushed the fix/gcs-bad-request-error branch from 3d98d7b to e88f477 Compare July 26, 2025 03:20
@hassiebp hassiebp removed their assignment Jul 28, 2025
@hassiebp hassiebp self-requested a review July 28, 2025 12:52
@hassiebp hassiebp merged commit 172a78c into langfuse:main Aug 27, 2025
1 check was pending
@hassiebp
Copy link
Contributor

Thanks for your contribution, @Jay-flow !

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.

bug: Media upload failed, Path: media.getById
3 participants