1 | |
2 | type Base64 = string |
3 | |
4 | * Upload a new project release file |
5 | * Upload a new file for the given release. |
6 |
|
7 | Unlike other API requests, files must be uploaded using the traditional multipart/form-data content-type. |
8 |
|
9 | Requests to this endpoint should use the region-specific domain eg. `us.sentry.io` or `de.sentry.io` |
10 |
|
11 | The optional 'name' attribute should reflect the absolute path that this file will be referenced as. For example, in the case of JavaScript you might specify the full web URI. |
12 | */ |
13 | export async function main( |
14 | auth: RT.Sentry, |
15 | project_id_or_slug: string, |
16 | version: string, |
17 | body: Body |
18 | ) { |
19 | const url = new URL( |
20 | `https://${auth.region}.sentry.io/api/0/projects/${auth.organizationSlug}/${project_id_or_slug}/releases/${version}/files/` |
21 | ) |
22 |
|
23 | const formData = new FormData() |
24 | for (const [k, v] of Object.entries(body)) { |
25 | if (v !== undefined && v !== '') { |
26 | if (['file'].includes(k)) { |
27 | const { base64, type, name } = v as { |
28 | base64: Base64 |
29 | type: string |
30 | name: string |
31 | } |
32 | formData.append( |
33 | k, |
34 | new Blob([Uint8Array.from(atob(base64), (m) => m.codePointAt(0)!)], { type }), |
35 | name |
36 | ) |
37 | } else { |
38 | formData.append(k, String(v)) |
39 | } |
40 | } |
41 | } |
42 | const response = await fetch(url, { |
43 | method: 'POST', |
44 | headers: { |
45 | Authorization: 'Bearer ' + auth.token |
46 | }, |
47 | body: formData |
48 | }) |
49 | if (!response.ok) { |
50 | const text = await response.text() |
51 | throw new Error(`${response.status} ${text}`) |
52 | } |
53 | return await response.json() |
54 | } |
55 |
|
56 | |
57 | |
58 | * This file was automatically generated by json-schema-to-typescript. |
59 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
60 | * and run json-schema-to-typescript to regenerate this file. |
61 | */ |
62 |
|
63 | export interface Body { |
64 | |
65 | * The multipart encoded file. |
66 | */ |
67 | file: { |
68 | base64: Base64 |
69 | type: |
70 | | 'image/png' |
71 | | 'image/jpeg' |
72 | | 'image/gif' |
73 | | 'application/pdf' |
74 | | 'appication/json' |
75 | | 'text/csv' |
76 | | 'text/plain' |
77 | | 'audio/mpeg' |
78 | | 'audio/wav' |
79 | | 'video/mp4' |
80 | name: string |
81 | } |
82 | |
83 | * The name (full path) of the file. |
84 | */ |
85 | name?: string |
86 | |
87 | * The name of the dist. |
88 | */ |
89 | dist?: string |
90 | |
91 | * This parameter can be supplied multiple times to attach headers to the file. Each header is a string in the format `key:value`. For instance it can be used to define a content type. |
92 | */ |
93 | header?: string |
94 | [k: string]: unknown |
95 | } |
96 |
|