mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-27 01:40:33 -04:00
fix: read S3 files with long non-ASCII names (#30418)
With S3 storage, a file whose stored name is close to the 255-byte filename limit and contains non-ASCII characters (for example a Cyrillic name of about 210-218 bytes) uploads fine, but every later read fails with "File name too long". Processing never gets the content, so the file shows as attached while the model receives no text. The read path used boto3's download_file, which first writes to a temporary name with 9 extra characters. boto3 caps that temporary name by characters, not bytes, so multibyte names end up over the limit even though the final name fits. The download now streams straight into the local path with download_fileobj, the same way the Azure provider already writes its local copy. That path is the one the upload just wrote successfully, so it always fits. ASCII names, key prefixes and multipart downloads behave as before. Fixes #30409
This commit is contained in:
@@ -168,7 +168,9 @@ class S3StorageProvider(StorageProvider):
|
||||
try:
|
||||
s3_key = self._extract_s3_key(file_path)
|
||||
local_file_path = self._get_local_file_path(s3_key)
|
||||
self.s3_client.download_file(self.bucket_name, s3_key, local_file_path)
|
||||
# download_file's temp name caps characters, not bytes, so non-ASCII names can exceed NAME_MAX
|
||||
with open(local_file_path, 'wb') as local_file:
|
||||
self.s3_client.download_fileobj(self.bucket_name, s3_key, local_file)
|
||||
return local_file_path
|
||||
except ClientError as e:
|
||||
raise RuntimeError(f'Error downloading file from S3: {e}')
|
||||
|
||||
Reference in New Issue
Block a user