0

Upload a new file

by
Published Oct 17, 2025

Upload a new debug information file for the given release. Unlike other API requests, files must be uploaded using the traditional multipart/form-data content-type. Requests to this endpoint should use the region-specific domain eg. `us.sentry.io` or `de.sentry.io`. The file uploaded is a zip archive of an Apple .dSYM folder which contains the individual debug images. Uploading through this endpoint will create different files for the contained images.

Script sentry Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Base64 = string
3
/**
4
 * Upload a new file
5
 * Upload a new debug information file for the given release.
6

7
Unlike other API requests, files must be uploaded using the
8
traditional multipart/form-data content-type.
9

10
Requests to this endpoint should use the region-specific domain eg. `us.sentry.io` or `de.sentry.io`.
11

12
The file uploaded is a zip archive of an Apple .dSYM folder which
13
contains the individual debug images.  Uploading through this endpoint
14
will create different files for the contained images.
15
 */
16
export async function main(auth: RT.Sentry, project_id_or_slug: string, body: Body) {
17
	const url = new URL(
18
		`https://${auth.region}.sentry.io/api/0/projects/${auth.organizationSlug}/${project_id_or_slug}/files/dsyms/`
19
	)
20

21
	const formData = new FormData()
22
	for (const [k, v] of Object.entries(body)) {
23
		if (v !== undefined && v !== '') {
24
			if (['file'].includes(k)) {
25
				const { base64, type, name } = v as {
26
					base64: Base64
27
					type: string
28
					name: string
29
				}
30
				formData.append(
31
					k,
32
					new Blob([Uint8Array.from(atob(base64), (m) => m.codePointAt(0)!)], { type }),
33
					name
34
				)
35
			} else {
36
				formData.append(k, String(v))
37
			}
38
		}
39
	}
40
	const response = await fetch(url, {
41
		method: 'POST',
42
		headers: {
43
			Authorization: 'Bearer ' + auth.token
44
		},
45
		body: formData
46
	})
47
	if (!response.ok) {
48
		const text = await response.text()
49
		throw new Error(`${response.status} ${text}`)
50
	}
51
	return await response.json()
52
}
53

54
/* eslint-disable */
55
/**
56
 * This file was automatically generated by json-schema-to-typescript.
57
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
58
 * and run json-schema-to-typescript to regenerate this file.
59
 */
60

61
export interface Body {
62
	/**
63
	 * The multipart encoded file.
64
	 */
65
	file: {
66
		base64: Base64
67
		type:
68
			| 'image/png'
69
			| 'image/jpeg'
70
			| 'image/gif'
71
			| 'application/pdf'
72
			| 'appication/json'
73
			| 'text/csv'
74
			| 'text/plain'
75
			| 'audio/mpeg'
76
			| 'audio/wav'
77
			| 'video/mp4'
78
		name: string
79
	}
80
	[k: string]: unknown
81
}
82