Skip to content

fix: use correct MIME type for file uploads #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath"
version = "2.0.69"
version = "2.0.70"
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion src/uipath/_cli/cli_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def pack_fn(projectName, description, entryPoints, version, authors, directory):
file_extensions_included = [".py", ".mermaid", ".json", ".yaml", ".yml"]
files_included = []
# Binary files that should be read in binary mode
binary_extensions = [".exe", ""]
binary_extensions = [".exe", "", ".xlsx", ".xls"]

with open(config_path, "r") as f:
config_data = json.load(f)
Expand Down
44 changes: 34 additions & 10 deletions src/uipath/_services/buckets_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import mimetypes
from typing import Any, Dict, Optional, Union

import httpx
Expand Down Expand Up @@ -154,7 +155,7 @@ def upload(
key: Optional[str] = None,
name: Optional[str] = None,
blob_file_path: str,
content_type: str,
content_type: Optional[str] = None,
source_path: Optional[str] = None,
content: Optional[Union[str, bytes]] = None,
folder_key: Optional[str] = None,
Expand All @@ -166,7 +167,7 @@ def upload(
key (Optional[str]): The key of the bucket.
name (Optional[str]): The name of the bucket.
blob_file_path (str): The path where the file will be stored in the bucket.
content_type (str): The MIME type of the file.
content_type (Optional[str]): The MIME type of the file. For file inputs this is computed dynamically. Default is "application/octet-stream".
source_path (Optional[str]): The local path of the file to upload.
content (Optional[Union[str, bytes]]): The content to upload (string or bytes).
folder_key (Optional[str]): The key of the folder where the bucket resides.
Expand All @@ -185,9 +186,17 @@ def upload(
name=name, key=key, folder_key=folder_key, folder_path=folder_path
)

# if source_path, dynamically detect the mime type
# default to application/octet-stream
if source_path:
_content_type, _ = mimetypes.guess_type(source_path)
else:
_content_type = content_type
_content_type = _content_type or "application/octet-stream"

spec = self._retrieve_writeri_spec(
bucket.id,
content_type,
_content_type,
blob_file_path,
folder_key=folder_key,
folder_path=folder_path,
Expand All @@ -209,6 +218,8 @@ def upload(
)
}

headers["Content-Type"] = _content_type

if content is not None:
if isinstance(content, str):
content = content.encode("utf-8")
Expand All @@ -220,13 +231,14 @@ def upload(

if source_path is not None:
with open(source_path, "rb") as file:
file_content = file.read()
if result["RequiresAuth"]:
self.request(
"PUT", write_uri, headers=headers, files={"file": file}
"PUT", write_uri, headers=headers, content=file_content
)
else:
self.custom_client.put(
write_uri, headers=headers, files={"file": file}
write_uri, headers=headers, content=file_content
)

@traced(name="buckets_upload", run_type="uipath")
Expand All @@ -237,7 +249,7 @@ async def upload_async(
key: Optional[str] = None,
name: Optional[str] = None,
blob_file_path: str,
content_type: str,
content_type: Optional[str] = None,
source_path: Optional[str] = None,
content: Optional[Union[str, bytes]] = None,
folder_key: Optional[str] = None,
Expand All @@ -249,8 +261,9 @@ async def upload_async(
key (Optional[str]): The key of the bucket.
name (Optional[str]): The name of the bucket.
blob_file_path (str): The path where the file will be stored in the bucket.
content_type (str): The MIME type of the file.
content_type (Optional[str]): The MIME type of the file. For file inputs this is computed dynamically. Default is "application/octet-stream".
source_path (str): The local path of the file to upload.
content (Optional[Union[str, bytes]]): The content to upload (string or bytes).
folder_key (Optional[str]): The key of the folder where the bucket resides.
folder_path (Optional[str]): The path of the folder where the bucket resides.

Expand All @@ -267,9 +280,17 @@ async def upload_async(
name=name, key=key, folder_key=folder_key, folder_path=folder_path
)

# if source_path, dynamically detect the mime type
# default to application/octet-stream
if source_path:
_content_type, _ = mimetypes.guess_type(source_path)
else:
_content_type = content_type
_content_type = _content_type or "application/octet-stream"

spec = self._retrieve_writeri_spec(
bucket.id,
content_type,
_content_type,
blob_file_path,
folder_key=folder_key,
folder_path=folder_path,
Expand All @@ -293,6 +314,8 @@ async def upload_async(
)
}

headers["Content-Type"] = _content_type

if content is not None:
if isinstance(content, str):
content = content.encode("utf-8")
Expand All @@ -308,13 +331,14 @@ async def upload_async(

if source_path is not None:
with open(source_path, "rb") as file:
file_content = file.read()
if result["RequiresAuth"]:
await self.request_async(
"PUT", write_uri, headers=headers, files={"file": file}
"PUT", write_uri, headers=headers, content=file_content
)
else:
await self.custom_client_async.put(
write_uri, headers=headers, files={"file": file}
write_uri, headers=headers, content=file_content
)

@traced(name="buckets_retrieve", run_type="uipath")
Expand Down
8 changes: 4 additions & 4 deletions src/uipath/_services/context_grounding_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def __init__(
def add_to_index(
self,
name: str,
content_type: str,
blob_file_path: str,
content_type: Optional[str] = None,
content: Optional[Union[str, bytes]] = None,
source_path: Optional[str] = None,
folder_key: Optional[str] = None,
Expand All @@ -62,7 +62,7 @@ def add_to_index(

Args:
name (str): The name of the index to add content to.
content_type (str): The type of content being added.
content_type (Optional[str]): The MIME type of the file. For file inputs this is computed dynamically. Default is "application/octet-stream".
blob_file_path (str): The path where the blob will be stored in the storage bucket.
content (Optional[Union[str, bytes]]): The content to be added, either as a string or bytes.
source_path (Optional[str]): The source path of the content if it is being uploaded from a file.
Expand Down Expand Up @@ -105,8 +105,8 @@ def add_to_index(
async def add_to_index_async(
self,
name: str,
content_type: str,
blob_file_path: str,
content_type: Optional[str] = None,
content: Optional[Union[str, bytes]] = None,
source_path: Optional[str] = None,
folder_key: Optional[str] = None,
Expand All @@ -117,7 +117,7 @@ async def add_to_index_async(

Args:
name (str): The name of the index to add content to.
content_type (str): The type of content being added.
content_type (Optional[str]): The MIME type of the file. For file inputs this is computed dynamically. Default is "application/octet-stream".
blob_file_path (str): The path where the blob will be stored in the storage bucket.
content (Optional[Union[str, bytes]]): The content to be added, either as a string or bytes.
source_path (Optional[str]): The source path of the content if it is being uploaded from a file.
Expand Down
1 change: 0 additions & 1 deletion tests/sdk/services/test_buckets_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ def test_upload_from_path(
assert sent_requests[2].url == "https://test-storage.com/test-file.txt"

assert b"test content" in sent_requests[2].content
assert b"Content-Disposition: form-data;" in sent_requests[2].content

def test_upload_from_memory(
self,
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.