//native
type Box = {
token: string;
};
/**
* Commit upload session
* Close an upload session and create a file from the uploaded chunks.
The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions)
and [`Get upload session`](e://get-files-upload-sessions-id) endpoints.
*/
export async function main(
auth: Box,
upload_session_id: string,
digest: string,
if_match: string,
if_none_match: string,
body: {
parts: { part_id?: string; offset?: number; size?: number } & {
sha1?: string;
}[];
},
) {
const url = new URL(
`https://api.box.com/2.0/files/upload_sessions/${upload_session_id}/commit`,
);
const response = await fetch(url, {
method: "POST",
headers: {
digest: digest,
"if-match": if_match,
"if-none-match": if_none_match,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago