Skip to content

Commit 2d6500f

Browse files
shah-sidddgustavocidornelas
authored andcommitted
fix(upload.py): fix upload for local
1 parent 1941e5f commit 2d6500f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/openlayer/lib/data/_upload.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ def upload_bytes_multipart(
115115
if isinstance(data, bytes):
116116
data = io.BytesIO(data)
117117

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

120122
encoder = MultipartEncoder(fields=upload_fields)

src/openlayer/lib/tracing/attachment_uploader.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,24 @@ def upload_attachment(self, attachment: "Attachment") -> "Attachment":
130130
if file_bytes is None:
131131
raise ValueError(f"No data available for attachment {attachment.name}")
132132

133-
# Upload using the shared upload function
133+
# Upload using the shared upload function.
134+
# presigned_response.fields is None for local storage (only S3 needs policy fields)
135+
try:
136+
fields = (
137+
dict(presigned_response.fields)
138+
if presigned_response.fields is not None
139+
else {}
140+
)
141+
except (TypeError, ValueError):
142+
fields = {}
143+
134144
upload_bytes(
135145
storage=self._storage,
136146
url=presigned_response.url,
137147
data=file_bytes,
138148
object_name=object_name,
139149
content_type=attachment.media_type,
140-
fields=(
141-
dict(presigned_response.fields)
142-
if presigned_response.fields
143-
else None
144-
),
150+
fields=fields,
145151
)
146152

147153
# Set the storage URI on the attachment

0 commit comments

Comments
 (0)