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

Function toFile

packages/core/src/v3/apiClient/core.ts:370–400  ·  view source on GitHub ↗
(
  value: ToFileInput | PromiseLike<ToFileInput>,
  name?: string | null | undefined,
  options?: FilePropertyBag | undefined
)

Source from the content-addressed store, hash-verified

368 * @returns a {@link File} with the given properties
369 */
370export async function toFile(
371 value: ToFileInput | PromiseLike<ToFileInput>,
372 name?: string | null | undefined,
373 options?: FilePropertyBag | undefined
374): Promise<FileLike> {
375 // If it's a promise, resolve it.
376 value = await value;
377
378 // Use the file's options if there isn't one provided
379 options ??= isFileLike(value) ? { lastModified: value.lastModified, type: value.type } : {};
380
381 if (isResponseLike(value)) {
382 const blob = await value.blob();
383 name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? "unknown_file";
384
385 return new File([blob as any], name, options);
386 }
387
388 const bits = await getBytes(value);
389
390 name ||= getName(value) ?? "unknown_file";
391
392 if (!options.type) {
393 const type = (bits[0] as any)?.type;
394 if (typeof type === "string") {
395 options = { ...options, type };
396 }
397 }
398
399 return new File(bits, name, options);
400}
401
402function getName(value: any): string | undefined {
403 return (

Callers 4

addFormValueFunction · 0.85
createMethod · 0.85
createFineTuneMethod · 0.85

Calls 5

isFileLikeFunction · 0.85
isResponseLikeFunction · 0.85
getBytesFunction · 0.85
getNameFunction · 0.85
blobMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…