MCPcopy Index your code
hub / github.com/AnswerOverflow/AnswerOverflow / uploadFileFromUrl

Function uploadFileFromUrl

packages/core/src/files.ts:15–38  ·  view source on GitHub ↗
(file: {
	id: string;
	filename: string;
	contentType?: string;
	url: string;
})

Source from the content-addressed store, hash-verified

13});
14
15export async function uploadFileFromUrl(file: {
16 id: string;
17 filename: string;
18 contentType?: string;
19 url: string;
20}) {
21 if (sharedEnvs.NODE_ENV === 'test') return null;
22 const res = await fetch(file.url);
23 if (!res.ok || !res.body) return null;
24 const stream = Readable.fromWeb(
25 res.body as unknown as ReadableStream<Uint8Array>,
26 );
27 return new Upload({
28 client: s3bucket,
29 params: {
30 Bucket: sharedEnvs.BUCKET_NAME as string,
31
32 Key: `${file.id}/${file.filename}`,
33 Body: stream,
34 ContentDisposition: 'inline',
35 ContentType: file.contentType,
36 },
37 }).done();
38}
39
40export async function uploadFile(file: {
41 filename: string;

Callers 3

updateAttachmentsFunction · 0.90
fastUpsertManyMessagesFunction · 0.90
autoUpdateServerInfoFunction · 0.90

Calls 1

fetchFunction · 0.85

Tested by

no test coverage detected