0

Create file

by
Published Nov 5, 2024

Returns metadata that can be used to upload a file to the server and then attach it to a resource.

Script motimate Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Motimate = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Motimate,
8
	body: {
9
		file_name: string
10
		file_type: 'document' | 'image' | 'video'
11
		content_length: number
12
	}
13
) {
14
	const url = new URL(`https://motimateapp.com/public_api/files`)
15

16
	const response = await fetch(url, {
17
		method: 'POST',
18
		headers: {
19
			'Content-Type': 'application/json',
20
			Authorization: 'Bearer ' + auth.token
21
		},
22
		body: JSON.stringify(body)
23
	})
24

25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29

30
	return await response.json()
31
}
32