MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / uploadToObjectStore

Function uploadToObjectStore

apps/webapp/app/v3/r2.server.ts:20–52  ·  view source on GitHub ↗
(
  filename: string,
  data: string,
  contentType: string,
  environment: AuthenticatedEnvironment
)

Source from the content-addressed store, hash-verified

18}
19
20export async function uploadToObjectStore(
21 filename: string,
22 data: string,
23 contentType: string,
24 environment: AuthenticatedEnvironment
25): Promise<string> {
26 if (!r2) {
27 throw new Error("Object store credentials are not set");
28 }
29
30 if (!env.OBJECT_STORE_BASE_URL) {
31 throw new Error("Object store base URL is not set");
32 }
33
34 const url = new URL(env.OBJECT_STORE_BASE_URL);
35 url.pathname = `/packets/${environment.project.externalRef}/${environment.slug}/${filename}`;
36
37 logger.debug("Uploading to object store", { url: url.href });
38
39 const response = await r2.fetch(url.toString(), {
40 method: "PUT",
41 headers: {
42 "Content-Type": contentType,
43 },
44 body: data,
45 });
46
47 if (!response.ok) {
48 throw new Error(`Failed to upload output to ${url}: ${response.statusText}`);
49 }
50
51 return url.href;
52}

Callers 1

#handlePayloadPacketMethod · 0.90

Calls 3

fetchMethod · 0.80
toStringMethod · 0.80
debugMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…