MCPcopy Create free account
hub / github.com/ScattrdBlade/bigFileUpload / uploadToTmpfiles

Function uploadToTmpfiles

utils/upload.ts:778–807  ·  view source on GitHub ↗
(fileBlob: Blob, filename: string)

Source from the content-addressed store, hash-verified

776}
777
778async function uploadToTmpfiles(fileBlob: Blob, filename: string): Promise<string> {
779 if (Native) {
780 const result = await Native.uploadToTmpfiles(await fileBlob.arrayBuffer(), filename);
781 if (!result.success || !result.url) throw new Error(result.error || "No URL returned from upload");
782 return result.url;
783 }
784
785 const formData = new FormData();
786 formData.append("file", fileBlob, filename);
787
788 const uploadUrl = "https://tmpfiles.org/api/v1/upload";
789 const response = await uploadRequestWithTimeout(uploadUrl, {
790 method: "POST",
791 body: formData
792 });
793
794 if (!response.ok) {
795 throw new Error(`Upload failed: ${response.status} ${await response.text()}`);
796 }
797
798 const data = await response.json() as { status?: string; data?: { url?: string; }; };
799 const url = data.data?.url;
800 if (!url || data.status !== "success") {
801 throw new Error("No URL returned from upload");
802 }
803
804 return url.includes("tmpfiles.org/") && !url.includes("/dl/")
805 ? url.replace(/tmpfiles\.org\/(\d+)/, "tmpfiles.org/dl/$1")
806 : url;
807}
808
809async function uploadToBuzzheavier(fileBlob: Blob, filename: string): Promise<string> {
810 if (Native) {

Callers 1

uploadToServiceFunction · 0.70

Calls 3

uploadRequestWithTimeoutFunction · 0.85
textMethod · 0.80
jsonMethod · 0.80

Tested by

no test coverage detected