0

Upload Deployment Files

by
Published Apr 8, 2025

Before you create a deployment you need to upload the required files for that deployment. To do it, you need to first upload each file to this endpoint. Once that's completed, you can create a new deployment with the uploaded files. The file content must be placed inside the body of the request. In the case of a successful response you'll receive a status code 200 with an empty body.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Upload Deployment Files
7
 * Before you create a deployment you need to upload the required files for that deployment. To do it, you need to first upload each file to this endpoint. Once that's completed, you can create a new deployment with the uploaded files. The file content must be placed inside the body of the request. In the case of a successful response you'll receive a status code 200 with an empty body.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  teamId: string | undefined,
12
  slug: string | undefined,
13
  Content_Length?: string,
14
  x_vercel_digest?: string,
15
  x_now_digest?: string,
16
  x_now_size?: string,
17
) {
18
  const url = new URL(`https://api.vercel.com/v2/files`);
19
  for (const [k, v] of [
20
    ["teamId", teamId],
21
    ["slug", slug],
22
  ]) {
23
    if (v !== undefined && v !== "" && k !== undefined) {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "POST",
29
    headers: {
30
      ...(Content_Length ? { "Content-Length": Content_Length } : {}),
31
      ...(x_vercel_digest ? { "x-vercel-digest": x_vercel_digest } : {}),
32
      ...(x_now_digest ? { "x-now-digest": x_now_digest } : {}),
33
      ...(x_now_size ? { "x-now-size": x_now_size } : {}),
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44