1 | |
2 | type Base64 = string |
3 | |
4 | * Upload a new organization 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(auth: RT.Sentry, version: string, body: Body) { |
14 | const url = new URL( |
15 | `https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/releases/${version}/files/` |
16 | ) |
17 |
|
18 | const formData = new FormData() |
19 | for (const [k, v] of Object.entries(body)) { |
20 | if (v !== undefined && v !== '') { |
21 | if (['file'].includes(k)) { |
22 | const { base64, type, name } = v as { |
23 | base64: Base64 |
24 | type: string |
25 | name: string |
26 | } |
27 | formData.append( |
28 | k, |
29 | new Blob([Uint8Array.from(atob(base64), (m) => m.codePointAt(0)!)], { type }), |
30 | name |
31 | ) |
32 | } else { |
33 | formData.append(k, String(v)) |
34 | } |
35 | } |
36 | } |
37 | const response = await fetch(url, { |
38 | method: 'POST', |
39 | headers: { |
40 | Authorization: 'Bearer ' + auth.token |
41 | }, |
42 | body: formData |
43 | }) |
44 | if (!response.ok) { |
45 | const text = await response.text() |
46 | throw new Error(`${response.status} ${text}`) |
47 | } |
48 | return await response.text() |
49 | } |
50 |
|
51 | |
52 | |
53 | * This file was automatically generated by json-schema-to-typescript. |
54 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
55 | * and run json-schema-to-typescript to regenerate this file. |
56 | */ |
57 |
|
58 | export interface Body { |
59 | |
60 | * The multipart encoded file. |
61 | */ |
62 | file: { |
63 | base64: Base64 |
64 | type: |
65 | | 'image/png' |
66 | | 'image/jpeg' |
67 | | 'image/gif' |
68 | | 'application/pdf' |
69 | | 'appication/json' |
70 | | 'text/csv' |
71 | | 'text/plain' |
72 | | 'audio/mpeg' |
73 | | 'audio/wav' |
74 | | 'video/mp4' |
75 | name: string |
76 | } |
77 | |
78 | * The name (full path) of the file. |
79 | */ |
80 | name?: string |
81 | |
82 | * The name of the dist. |
83 | */ |
84 | dist?: string |
85 | |
86 | * 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. |
87 | */ |
88 | header?: string |
89 | [k: string]: unknown |
90 | } |
91 |
|