A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
[Bugfix] Unquote file uri before reading image (#22912)
Signed-off-by: Sayandip Dutta <sayandip199309@gmail.com> Co-authored-by: Cyrus Leung <cyrus.tl.leung@gmail.com>
Sayandip Dutta committed
Aug 15, 2025 at 14:58 UTC
aa300c438dad029ac308e0b6fcc2bae9ac689f8c
2 files changed
+28
-1
tests/multimodal/test_utils.py
+26
@@ -148,6 +148,32 @@ async def test_fetch_image_local_files(image_url: str):
148
f"file://{temp_dir}/../{os.path.basename(image_url)}")
149
150
151
+@pytest.mark.asyncio
152
+async def test_fetch_image_local_files_with_space_in_name():
153
+ image_url = TEST_IMAGE_URLS[0]
154
+ connector = MediaConnector()
155
+
156
+ with TemporaryDirectory() as temp_dir:
157
+ local_connector = MediaConnector(allowed_local_media_path=temp_dir)
158
+
159
+ origin_image = connector.fetch_image(image_url)
160
+ filename = "file name with space.jpg"
161
+ origin_image.save(os.path.join(temp_dir, filename),
162
+ quality=100,
163
+ icc_profile=origin_image.info.get('icc_profile'))
164
+
165
+ try:
166
+ image_async = await local_connector.fetch_image_async(
167
+ f"file://{temp_dir}/{filename}")
168
+ image_sync = local_connector.fetch_image(
169
+ f"file://{temp_dir}/{filename}")
170
+ except FileNotFoundError as e:
171
+ pytest.fail(
172
+ "Failed to fetch image with space in name: {}".format(e))
173
+ # Check that the images are equal
174
+ assert not ImageChops.difference(image_sync, image_async).getbbox()
175
+
176
+
177
@pytest.mark.asyncio
178
async def test_fetch_image_error_conversion():
179
connector = MediaConnector()
vllm/multimodal/utils.py
+2
-1
@@ -9,6 +9,7 @@ from itertools import groupby
9
from pathlib import Path
10
from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union
11
from urllib.parse import ParseResult, urlparse
12
+from urllib.request import url2pathname
13
14
import numpy as np
15
import numpy.typing as npt
@@ -108,7 +109,7 @@ class MediaConnector:
109
raise RuntimeError("Cannot load local files without "
110
"`--allowed-local-media-path`.")
111
111
- filepath = Path(url_spec.path)
112
+ filepath = Path(url2pathname(url_spec.path))
113
if allowed_local_media_path not in filepath.resolve().parents:
114
raise ValueError(
115
f"The file path {filepath} must be a subpath "