Skip to content
Open
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: 2 additions & 0 deletions src/openlayer/lib/data/_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def upload_bytes_multipart(
if isinstance(data, bytes):
data = io.BytesIO(data)

# fields can be None when using local storage (presigned URL has no S3 policy fields)
fields = fields or {}
upload_fields = {"file": (object_name, data, content_type), **fields}

encoder = MultipartEncoder(fields=upload_fields)
Expand Down
18 changes: 12 additions & 6 deletions src/openlayer/lib/tracing/attachment_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,24 @@ def upload_attachment(self, attachment: "Attachment") -> "Attachment":
if file_bytes is None:
raise ValueError(f"No data available for attachment {attachment.name}")

# Upload using the shared upload function
# Upload using the shared upload function.
# presigned_response.fields is None for local storage (only S3 needs policy fields)
try:
fields = (
dict(presigned_response.fields)
if presigned_response.fields is not None
else {}
)
except (TypeError, ValueError):
fields = {}

upload_bytes(
storage=self._storage,
url=presigned_response.url,
data=file_bytes,
object_name=object_name,
content_type=attachment.media_type,
fields=(
dict(presigned_response.fields)
if presigned_response.fields
else None
),
fields=fields,
)

# Set the storage URI on the attachment
Expand Down