0

Generates batches of presigned URLs for multipart parts

Published Oct 17, 2025

Multipart uploads are uploaded in chunks or parts to individual presigned URLs, similar to the one generated by /generate-presigned-put.

Script discourse Verified

The script

Submitted by hugo697 Bun
Verified 397 days ago
1
//native
2
type Discourse = {
3
  apiKey: string;
4
  defaultHost: string;
5
  apiUsername: string;
6
};
7
/**
8
 * Generates batches of presigned URLs for multipart parts
9
 * Multipart uploads are uploaded in chunks or parts to individual presigned
10
URLs, similar to the one generated by /generate-presigned-put.
11
 */
12
export async function main(
13
  auth: Discourse,
14
  body: { part_numbers: unknown[]; unique_identifier: string },
15
) {
16
  const url = new URL(
17
    `https://${auth.defaultHost}/uploads/batch-presign-multipart-parts.json`,
18
  );
19

20
  const response = await fetch(url, {
21
    method: "POST",
22
    headers: {
23
      "Content-Type": "application/json",
24
      "API-KEY": auth.apiKey,
25
      "API-USERNAME": auth.apiUsername,
26
    },
27
    body: JSON.stringify(body),
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35