Trying to sanitize the file names

This commit is contained in:
2026-06-05 08:18:41 -07:00
parent 0f44ea375d
commit ed3a861214
+12 -3
View File
@@ -193,9 +193,18 @@ def main():
print(f"Warning: File '{file_path}' not found. Skipping.", file=sys.stderr) print(f"Warning: File '{file_path}' not found. Skipping.", file=sys.stderr)
continue continue
print(f"Uploading '{file_path}'...") # Sanitize the filename for HTTP headers (replace non-ASCII with underscores)
uploaded_file = client.files.upload(file=file_path) base_name = os.path.basename(file_path)
print(f"Success: '{file_path}' uploaded as '{uploaded_file.name}'") safe_name = "".join([c if ord(c) < 128 else "_" for c in base_name])
print(f"Uploading '{file_path}'...", file=sys.stderr)
# Force the SDK to use our sanitized name for the upload display name
uploaded_file = client.files.upload(
file=file_path,
config={'display_name': safe_name}
)
print(f"Success: '{file_path}' uploaded as '{uploaded_file.name}'", file=sys.stderr)
if uploaded_file.name not in context_data["file_ids"]: if uploaded_file.name not in context_data["file_ids"]:
context_data["file_ids"].append(uploaded_file.name) context_data["file_ids"].append(uploaded_file.name)