Skip to content

Conversation

@sgao640
Copy link
Contributor

@sgao640 sgao640 commented Oct 28, 2025

@sgao640
Copy link
Contributor Author

sgao640 commented Oct 29, 2025

Fix Missing Object Metadata in UploadDerivedContent

Problem

The UploadDerivedContent() method was missing proper object metadata handling, which caused derived content (thumbnails, previews, transcodes) to lack important metadata like file size and MIME type.

Solution

This PR adds comprehensive object metadata handling to the derived content upload workflow.

Changes in pkg/simplecontent/service_impl.go

1. Create Object Metadata Entry (Step 7)

// Step 7: Create object metadata
objectMetadata := &ObjectMetadata{
    ObjectID:  objectID,
    CreatedAt: now,
    UpdatedAt: now,
}
if err := s.repository.SetObjectMetadata(ctx, objectMetadata); err != nil {
    return nil, &ObjectError{
        ObjectID: objectID,
        Op:       "upload_object_metadata_create",
        Err:      err,
    }
}
  • Creates object metadata entry before uploading data
  • Ensures metadata tracking exists for the object

2. Update Object Metadata from Storage (Step 10)

// Step 10: Update object metadata
object_metadata, err := s.updateObjectFromStorage(ctx, objectID)
if err != nil {
    // Log warning but don't fail - object was uploaded successfully
}
  • Retrieves actual metadata from storage backend (file size, MIME type, etc.)
  • Non-blocking: logs warning on failure but doesn't fail the upload

3. Populate Content Metadata (Step 11)

if object_metadata != nil {
    metadata.FileSize = object_metadata.SizeBytes
    metadata.MimeType = object_metadata.MimeType
}
  • Enriches content metadata with storage metadata
  • Ensures file size and MIME type are accurately recorded

Impact

Before this fix:

  • Derived content objects had no metadata entries
  • File size and MIME type were missing or incorrect
  • Metadata queries for derived content returned incomplete data

After this fix:

  • ✅ Object metadata is created for all derived content
  • ✅ File size and MIME type are accurately captured from storage
  • ✅ Content metadata is complete and accurate
  • ✅ Consistent metadata handling across upload methods

Workflow Alignment

This fix aligns UploadDerivedContent() with the existing UploadContent() method, which already implements proper object metadata handling. Both methods now follow the same pattern:

  1. Create object metadata entry
  2. Upload data to storage
  3. Update object metadata from storage
  4. Populate content metadata with storage metadata

Testing

Verify the fix works correctly:

// Upload derived content (e.g., thumbnail)
derived, err := svc.UploadDerivedContent(ctx, UploadDerivedContentRequest{
    ParentID:       parentID,
    DerivationType: "thumbnail",
    Variant:        "thumbnail_256",
    Reader:         thumbReader,
    FileName:       "thumb_256.jpg",
})

// Check that metadata is populated
details, err := svc.GetContentDetails(ctx, derived.ID)
// details.Metadata.FileSize should be set (from storage)
// details.Metadata.MimeType should be set (from storage)

Files Changed

  • pkg/simplecontent/service_impl.go (+29, -6 lines)

🤖 Generated with Claude Code

@livefire2015 livefire2015 merged commit c136e71 into tendant:main Oct 29, 2025
1 of 7 checks passed
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.

2 participants