0

Complete multipart upload

by
Published Oct 17, 2025

Completes the multipart upload in the external store, and copies the file from its temporary location to its final location in the store.

Script discourse Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Discourse = {
3
  apiKey: string;
4
  defaultHost: string;
5
  apiUsername: string;
6
};
7
/**
8
 * Complete multipart upload
9
 * Completes the multipart upload in the external store, and copies the
10
file from its temporary location to its final location in the store.
11
 */
12
export async function main(
13
  auth: Discourse,
14
  body: { unique_identifier: string; parts: unknown[] },
15
) {
16
  const url = new URL(`https://${auth.defaultHost}/uploads/complete-multipart.json`);
17

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