UploadThing in a backend application

I'm trying to use uploadthing in my Discord Bot, since I don't have any routing or anything complex, I thought that using UTAPI SDK would be enough, but I'm facing a weird error. Whenever I try to use any method provided by UTApi errors with (FiberFailure) TypeError: Attempted to assign to readonly property. Full Error:
$ turbo dev --filter discord-bot
• Packages in scope: discord-bot
• Running dev in 1 packages
• Remote caching disabled
discord-bot:dev: cache bypass, force executing 79077e2ea62107d1
discord-bot:dev: $ bun --watch src/index.ts
discord-bot:dev: 937 | ...options,
discord-bot:dev: 938 | type: options?.type ?? (lookup(name) || "application/octet-stream"),
discord-bot:dev: 939 | lastModified: options?.lastModified ?? Date.now()
discord-bot:dev: 940 | };
discord-bot:dev: 941 | super(parts, optionsWithDefaults);
discord-bot:dev: 942 | this.name = name;
discord-bot:dev: ^
discord-bot:dev: (FiberFailure) TypeError: Attempted to assign to readonly property.
discord-bot:dev: at new UTFile (/home/fagner/code/dogbux/dogbux/node_modules/uploadthing/server/index.js:942:13)
discord-bot:dev: at /home/fagner/code/dogbux/dogbux/node_modules/uploadthing/server/index.js:1033:95
discord-bot:dev: at /home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/core.js:409:39
discord-bot:dev: at runLoop (/home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/fiberRuntime.js:1063:28)
discord-bot:dev: at evaluateEffect (/home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/fiberRuntime.js:696:27)
discord-bot:dev: at evaluateMessageWhileSuspended (/home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/fiberRuntime.js:671:16)
discord-bot:dev: at drainQueueOnCurrentThread (/home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/fiberRuntime.js:452:85)
discord-bot:dev: at /home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/fiberRuntime.js:1090:10
discord-bot:dev: at starveInternal (/home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/Scheduler.js:73:15)
$ turbo dev --filter discord-bot
• Packages in scope: discord-bot
• Running dev in 1 packages
• Remote caching disabled
discord-bot:dev: cache bypass, force executing 79077e2ea62107d1
discord-bot:dev: $ bun --watch src/index.ts
discord-bot:dev: 937 | ...options,
discord-bot:dev: 938 | type: options?.type ?? (lookup(name) || "application/octet-stream"),
discord-bot:dev: 939 | lastModified: options?.lastModified ?? Date.now()
discord-bot:dev: 940 | };
discord-bot:dev: 941 | super(parts, optionsWithDefaults);
discord-bot:dev: 942 | this.name = name;
discord-bot:dev: ^
discord-bot:dev: (FiberFailure) TypeError: Attempted to assign to readonly property.
discord-bot:dev: at new UTFile (/home/fagner/code/dogbux/dogbux/node_modules/uploadthing/server/index.js:942:13)
discord-bot:dev: at /home/fagner/code/dogbux/dogbux/node_modules/uploadthing/server/index.js:1033:95
discord-bot:dev: at /home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/core.js:409:39
discord-bot:dev: at runLoop (/home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/fiberRuntime.js:1063:28)
discord-bot:dev: at evaluateEffect (/home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/fiberRuntime.js:696:27)
discord-bot:dev: at evaluateMessageWhileSuspended (/home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/fiberRuntime.js:671:16)
discord-bot:dev: at drainQueueOnCurrentThread (/home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/fiberRuntime.js:452:85)
discord-bot:dev: at /home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/internal/fiberRuntime.js:1090:10
discord-bot:dev: at starveInternal (/home/fagner/code/dogbux/dogbux/node_modules/effect/dist/esm/Scheduler.js:73:15)
uploadthing: ^6.10.1 bun: 1.1.3
13 Replies
Fagner
FagnerOP8mo ago
I tried using the API but I couldn't understand how to use it.
// @/server/utapi.ts
import { env } from "@/env";
import { UTApi } from "uploadthing/server";

export const utapi = new UTApi({
apiKey: env.UPLOADTHING_SECRET
});

// @/index.ts
import { utapi } from "./server/utapi";

const url = "https://fastly.picsum.photos/id/604/200/200.jpg?hmac=qgFjxODI1hMBMfHo68VvLeji-zvG9y-iPYhyW0EkvOs";
utapi.uploadFilesFromUrl([url]);
// @/server/utapi.ts
import { env } from "@/env";
import { UTApi } from "uploadthing/server";

export const utapi = new UTApi({
apiKey: env.UPLOADTHING_SECRET
});

// @/index.ts
import { utapi } from "./server/utapi";

const url = "https://fastly.picsum.photos/id/604/200/200.jpg?hmac=qgFjxODI1hMBMfHo68VvLeji-zvG9y-iPYhyW0EkvOs";
utapi.uploadFilesFromUrl([url]);
julius
julius8mo ago
GitHub
class extending blob cant set name prop · Issue #10178 · oven-sh/...
What version of Bun is running? 1.1.2+c8d072c2a What platform is your computer? Darwin 23.2.0 arm64 arm What steps can reproduce the bug? Repo: https://github.com/juliusmarminge/bun-blob To test, r...
Fagner
FagnerOP8mo ago
So what should I do then? Wait for a fix or use some other workaround? I see you commented saying that using Buffer works fine, but I'm not sure if I should that or not. Btw, I'm okay with using the API but couldn't understand how to use it, is there any content or project example you could recommend? Thanks! :a_shyemoji:
julius
julius8mo ago
Im afraid waiting for a fix might be the way unfortunately…. That’s kinda life when bleeding on the edge with new stuff. I’ve had to go back to pnpm from bun on a numerous of projects due to weird behaviors and missing features But you should be able to use the native File class unless you need customId prop from UTFile
Fagner
FagnerOP8mo ago
That's exactly what I did initially, I moved from Bun to PNPM back again, because of some gRPC issues, but realized things are getting better and went back to Bun, now facing another issue :Sad:
julius
julius8mo ago
Yup :// Been there, done that
Fagner
FagnerOP8mo ago
It's a very very very completely idiot solution, but I just removed those lines and gave it a try. It worked but I lost the capability to send these informations, so my files are named in a way I don't want to. I really don't want to use any other service, really like UploadThing.
No description
julius
julius8mo ago
Do you use customId field? If not just send File’s. Or are you uploading from URLs?
Fagner
FagnerOP8mo ago
From urls.
julius
julius8mo ago
Could patch and change UTFile to File - although patching in Bun sucks too
Fagner
FagnerOP8mo ago
This here is exactly what Im doing
julius
julius8mo ago
You should be able to patch and change this line to be just a File and remove the customId (assuming you dont use that) https://github.com/pingdotgg/uploadthing/blob/c4ba73691f514e9a4e2da0e0326ce738395e9a2c/packages/uploadthing/src/sdk/utils.ts#L125
GitHub
uploadthing/packages/uploadthing/src/sdk/utils.ts at c4ba73691f514e...
File uploads for modern web devs. Contribute to pingdotgg/uploadthing development by creating an account on GitHub.
Fagner
FagnerOP8mo ago
Im gonna take a look in a second! Thank you so much.
Want results from more Discord servers?
Add your server