Skip to content

[Bug]: ImageParser ignores source_name / resource_name, temp file ID leaks into resource internal filename #2382

@honey634546-dev

Description

@honey634546-dev

Bug Description

When uploading an image via POST /api/v1/resources with source_name specified, the internal filename inside the resource directory still uses the original temp file name (e.g., upload_3ab9f7ac399845b1825813c2e4f21cf2.png) instead of the custom name.

This behavior is inconsistent with document types (Markdown, PDF), which correctly respect source_name.

Steps to Reproduce

# 1. Upload temp file
curl -X POST /api/v1/resources/temp_upload -F 'file=@photo.png'
# → { "temp_file_id": "upload_xxx.png" }

# 2. Create resource with source_name
curl -X POST /api/v1/resources \
  -H 'Content-Type: application/json' \
  -d '{
    "temp_file_id": "upload_xxx.png",
    "to": "viking://resources/my-agent/images/photo",
    "source_name": "photo.png"
  }'

# 3. List resource contents
curl /api/v1/fs/ls?uri=viking://resources/my-agent/images/photo

Expected Behavior

{ "uri": "viking://resources/my-agent/images/photo/photo.png" }

Actual Behavior

{ "uri": "viking://resources/my-agent/images/photo/upload_xxx.png" }

Minimal Reproducible Example

Error Logs

OpenViking Version

0.3.3

Python Version

3.11

Operating System

Linux

Model Backend

None

Additional Context

Root Cause

media_processor.py:175 sets resource_name for all file types:

parse_kwargs["resource_name"] = Path(source_name).stem if source_name else file_path.stem

MarkdownParser correctly reads this parameter (markdown.py:177):

explicit_name = kwargs.get("resource_name") or kwargs.get("source_name")
doc_title = Path(explicit_name).stem if explicit_name else Path(source_path).stem

However, ImageParser.parse() (parsers/media/image.py:105-107) completely ignores it and hardcodes the original filename:

original_filename = file_path.name.replace(" ", "_")   # always temp file name
stem = file_path.stem.replace(" ", "_")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions