UploadThing invalid secret error, invalid server config

Hi I'm using the UTapi and it stopped working with the new sdk API keys not sure what's going on this project uses Astro any help is appreciated thanks! src/server/uploadthing.ts
import { UTApi } from "uploadthing/server";

export const utapi = new UTApi();
import { UTApi } from "uploadthing/server";

export const utapi = new UTApi();
api route
import { utapi } from "src/server/uploadthing.ts";

const result = await utapi.uploadFiles(files);
import { utapi } from "src/server/uploadthing.ts";

const result = await utapi.uploadFiles(files);
Error msg
e: Error: Invalid upload result: {"data":null,"error":{"message":"Invalid token. A token is a base64 encoded JSON object matching { apiKey: string, appId: string, regions: string[] }.","_tag":"UploadThingError","name":"UploadThingError","code":"INVALID_SERVER_CONFIG","cause":{"_op":"InvalidData","path":["token"],"message":"((Uint8ArrayFromBase64 <-> (Uint8ArrayFromSelf <-> string)) <-> ((JsonString <-> unknown) <-> (Struct (Encoded side) <-> Struct (Type side))))\n└─ Encoded side transformation failure\n └─ (Uint8ArrayFromBase64 <-> (Uint8ArrayFromSelf <-> string))\n └─ Encoded side transformation failure\n └─ Uint8ArrayFromBase64\n └─ Transformation process failure\n └─ Invalid character _"}}}
at eval (/Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/src/pages/api/convert.ts:224:21)
at Array.map (<anonymous>)
at Worker.eval (/Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/src/pages/api/convert.ts:222:47)
e: Error: Invalid upload result: {"data":null,"error":{"message":"Invalid token. A token is a base64 encoded JSON object matching { apiKey: string, appId: string, regions: string[] }.","_tag":"UploadThingError","name":"UploadThingError","code":"INVALID_SERVER_CONFIG","cause":{"_op":"InvalidData","path":["token"],"message":"((Uint8ArrayFromBase64 <-> (Uint8ArrayFromSelf <-> string)) <-> ((JsonString <-> unknown) <-> (Struct (Encoded side) <-> Struct (Type side))))\n└─ Encoded side transformation failure\n └─ (Uint8ArrayFromBase64 <-> (Uint8ArrayFromSelf <-> string))\n └─ Encoded side transformation failure\n └─ Uint8ArrayFromBase64\n └─ Transformation process failure\n └─ Invalid character _"}}}
at eval (/Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/src/pages/api/convert.ts:224:21)
at Array.map (<anonymous>)
at Worker.eval (/Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/src/pages/api/convert.ts:222:47)
27 Replies
markr
markr2w ago
Can you share the first ~10 characters of the token you are using?
bed
bedOP2w ago
UPLOADTHING_TOKEN='eyJhcGlLZXkiOiJza19saXZlXzc1MWIzYz
markr
markr2w ago
And if you decode the toke, it follows the expected format like mentioned in the error?
bed
bedOP2w ago
I haven't tried let me see {"apiKey":"sk_live_751b3123412346324512341324123476b79c91af","appId":"fkz2323hfg","regions":["cle1"]} I changed the api key ofc lol
markr
markr2w ago
Hmm very strange, you definitely should not be getting that error. I am wondering if UTApi is not picking up on the token for some reason. Can you try manually passing it in the constructor?
export const utapi = new UTApi({
token: process.env.UPLOADTHING_TOKEN
});
export const utapi = new UTApi({
token: process.env.UPLOADTHING_TOKEN
});
bed
bedOP2w ago
let me see I think that might have worked not sure
TypeError: Cannot use 'in' operator to search for '_op' in undefined
at FiberRuntime.runLoop (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/internal/fiberRuntime.js:1091:21)
at FiberRuntime.evaluateEffect (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/internal/fiberRuntime.js:698:27)
at FiberRuntime.evaluateMessageWhileSuspended (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/internal/fiberRuntime.js:673:16)
at FiberRuntime.drainQueueOnCurrentThread (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/internal/fiberRuntime.js:454:85)
at Array.run (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/internal/fiberRuntime.js:1123:10)
at MixedScheduler.starveInternal (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/Scheduler.js:68:17)
at file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modu
TypeError: Cannot use 'in' operator to search for '_op' in undefined
at FiberRuntime.runLoop (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/internal/fiberRuntime.js:1091:21)
at FiberRuntime.evaluateEffect (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/internal/fiberRuntime.js:698:27)
at FiberRuntime.evaluateMessageWhileSuspended (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/internal/fiberRuntime.js:673:16)
at FiberRuntime.drainQueueOnCurrentThread (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/internal/fiberRuntime.js:454:85)
at Array.run (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/internal/fiberRuntime.js:1123:10)
at MixedScheduler.starveInternal (file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modules/uploadthing/node_modules/effect/dist/esm/Scheduler.js:68:17)
at file:///Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/node_modu
I think there's a bug that got introduced somewhere
markr
markr2w ago
cc @julius -- weird effect thing
julius
julius2w ago
try removing node_modules and then re-installing. we've bumped effect so maybe you have 2 now fighting eachother
bed
bedOP2w ago
just tested - still got the same error - removed lock file just in case as well
npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported

added 827 packages, and audited 828 packages in 1m

219 packages are looking for funding
run `npm fund` for details

2 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
npm audit fix --force

Run `npm audit` for details.
npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported

added 827 packages, and audited 828 packages in 1m

219 packages are looking for funding
run `npm fund` for details

2 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
npm audit fix --force

Run `npm audit` for details.
julius
julius2w ago
did you bump both uplaodthing and @uploadthing/react ?
bed
bedOP2w ago
oof no I don't think so "@uploadthing/react": "^7.0.2", "uploadthing": "^7.0.2",
julius
julius2w ago
Are those what you’re using now? Can you check the exact versions?
bed
bedOP2w ago
that's what I have in package.json I think so yes how so?
julius
julius2w ago
lockfile, node_moduels or pnpm ls uploadthing && pnpm ls @uploadthing(react i think?
bed
bedOP2w ago
[email protected] /Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai ├─┬ @uploadthing/[email protected] │ └── [email protected] deduped └── [email protected] [email protected] /Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai └── @uploadthing/[email protected] I check node modules as well to confirm these versions
julius
julius2w ago
Ok 👍 and what’s the error you’re getting now?
bed
bedOP2w ago
still the same error
Error processing worker message: Error: Invalid upload result: {"data":null,"error":{"message":"Invalid token. A token is a base64 encoded JSON object matching { apiKey: string, appId: string, regions: string[] }.","_tag":"UploadThingError","name":"UploadThingError","code":"INVALID_SERVER_CONFIG","cause":{"_op":"InvalidData","path":["token"],"message":"((Uint8ArrayFromBase64 <-> (Uint8ArrayFromSelf <-> string)) <-> ((JsonString <-> unknown) <-> (Struct (Encoded side) <-> Struct (Type side))))\n└─ Encoded side transformation failure\n └─ (Uint8ArrayFromBase64 <-> (Uint8ArrayFromSelf <-> string))\n └─ Encoded side transformation failure\n └─ Uint8ArrayFromBase64\n └─ Transformation process failure\n └─ Length must be a multiple of 4, but is 1"}}}
at eval (/Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/src/pages/api/convert.ts:224:21)
at Array.map (<anonymous>)
at Worker.eval (/Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/src/pages/api/convert.ts:222:47)
Error processing worker message: Error: Invalid upload result: {"data":null,"error":{"message":"Invalid token. A token is a base64 encoded JSON object matching { apiKey: string, appId: string, regions: string[] }.","_tag":"UploadThingError","name":"UploadThingError","code":"INVALID_SERVER_CONFIG","cause":{"_op":"InvalidData","path":["token"],"message":"((Uint8ArrayFromBase64 <-> (Uint8ArrayFromSelf <-> string)) <-> ((JsonString <-> unknown) <-> (Struct (Encoded side) <-> Struct (Type side))))\n└─ Encoded side transformation failure\n └─ (Uint8ArrayFromBase64 <-> (Uint8ArrayFromSelf <-> string))\n └─ Encoded side transformation failure\n └─ Uint8ArrayFromBase64\n └─ Transformation process failure\n └─ Length must be a multiple of 4, but is 1"}}}
at eval (/Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/src/pages/api/convert.ts:224:21)
at Array.map (<anonymous>)
at Worker.eval (/Users/malik/Desktop/Programs/naturual-language-file-conversion/file-converter-ai/src/pages/api/convert.ts:222:47)
julius
julius2w ago
🤨🤨🤨
bed
bedOP2w ago
should I update my package json?
julius
julius2w ago
try this? https://github.com/pingdotgg/uploadthing/blob/main/playground/app/layout.tsx#L43-L45 does that decode fine? i've only seen this error happen when there're multiple effect versions but if that's not the case i don't know what it could be is the repo open source?
bed
bedOP2w ago
its not could I dm it to you? dies this work with astro? I'm using uploadthing from the server
julius
julius2w ago
yea those lines need to run on the server
bed
bedOP2w ago
On it 13:43:41 [ERROR] UploadThingToken is not defined
markr
markr2w ago
did you
import { UploadThingToken } from "uploadthing/types";
import { UploadThingToken } from "uploadthing/types";
bed
bedOP2w ago
did just now 13:44:27 [ERROR] ((Uint8ArrayFromBase64 <-> (Uint8ArrayFromSelf <-> string)) <-> ((JsonString <-> unknown) <-> (Struct (Encoded side) <-> Struct (Type side)))) └─ Encoded side transformation failure └─ (Uint8ArrayFromBase64 <-> (Uint8ArrayFromSelf <-> string)) └─ Encoded side transformation failure └─ Uint8ArrayFromBase64 └─ Transformation process failure └─ Length must be a multiple of 4, but is 1 Stack trace: I think the env is not getting loaded correctly
console.log("process.env.UPLOADTHING_TOKEN", process.env.UPLOADTHING_TOKEN);
console.log("process.env.UPLOADTHING_TOKEN", process.env.UPLOADTHING_TOKEN);
process.env.UPLOADTHING_TOKEN c ^ that's the result its working! I'm not sure what was wrong - maybe the install I'm not sure Thanks guys
markr
markr2w ago
Definitley a weird issue glad you got it sorted though!
bed
bedOP2w ago
me too! this is what I'm building if you are intrested https://fileconverterai.com
File Converter AI
Astro description

Did you find this page helpful?