MCPcopy Create free account
hub / github.com/fontsource/fontsource / putObject

Function putObject

api/container/src/r2.ts:38–69  ·  view source on GitHub ↗
(
	key: string,
	body: Uint8Array,
	metadata: PutObjectMetadata = {},
)

Source from the content-addressed store, hash-verified

36 * Writes one object directly to the configured R2 bucket from the container.
37 */
38export const putObject = async (
39 key: string,
40 body: Uint8Array,
41 metadata: PutObjectMetadata = {},
42): Promise<void> => {
43 const headers: Record<string, string> = {
44 'Content-Length': String(body.byteLength),
45 };
46
47 if (metadata.cacheControl) {
48 headers['Cache-Control'] = metadata.cacheControl;
49 }
50
51 if (metadata.contentType) {
52 headers['Content-Type'] = metadata.contentType;
53 }
54
55 const response = await client.client.fetch(buildObjectUrl(key), {
56 method: 'PUT',
57 body: body.slice(),
58 headers,
59 });
60
61 if (!response.ok) {
62 const text = await response.text();
63 throw new Error(
64 `Failed to upload ${key}: ${response.status} ${text || response.statusText}`,
65 );
66 }
67
68 console.log(`[r2] PUT ${key} (${body.byteLength} bytes)`);
69};

Callers 2

uploadArtifactsFunction · 0.90
buildDownloadArtifactsFunction · 0.90

Calls 4

buildObjectUrlFunction · 0.85
fetchMethod · 0.65
textMethod · 0.65
logMethod · 0.65

Tested by

no test coverage detected