Skip to content

Commit ecd6b17

Browse files
committed
fix: stream upload
1 parent 8f05757 commit ecd6b17

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • packages/shared/storage

packages/shared/storage/r2.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,18 @@ export function createR2Storage(config: R2Config): Storage {
6969
},
7070

7171
async write(key: string, content: Uint8Array | string): Promise<void> {
72+
// Always convert to Uint8Array and set ContentLength to avoid
73+
// "Stream of unknown length" errors with S3-compatible storage
74+
const body = typeof content === "string"
75+
? new TextEncoder().encode(content)
76+
: content;
77+
7278
await client.send(
7379
new PutObjectCommand({
7480
Bucket: bucket,
7581
Key: key,
76-
Body: content,
82+
Body: body,
83+
ContentLength: body.length,
7784
}),
7885
);
7986
},

0 commit comments

Comments
 (0)