Uploadthing Expo is not reading the correct server URL

I'm using Expo with Uploadthing for a mobile app, testing it in Expo Go on IOS emulator on MacOS When I upload images I get the error Failed to parse response from UploadThing server After hours of debugging I found out that UploadThing was not reading the correct env variable (in the docs it says EXPO_PUBLIC_SERVER_URL) so I take a look in the uploadthing code files and find another variable EXPO_PUBLIC_SERVER_ORIGIN (in @uploadthing/expo/dist/index.js) which still did not work The only way to fix it was to change the way url is created in generateReactNativeHelpers from:
let url = new URL("http://localhost:8081/api/uploadthing");

try {
url = new URL(initOpts?.url ?? "/api/uploadthing", typeof window.location !== "undefined" ? window.location.origin : process.env.EXPO_PUBLIC_SERVER_ORIGIN ?? `http://${debuggerHost}`);
} catch (err) {
console.warn(`Failed to resolve URL from ${initOpts?.url?.toString()} and ${process.env.EXPO_PUBLIC_SERVER_ORIGIN} or ${debuggerHost}. Your application may not work as expected.`, err);
}
let url = new URL("http://localhost:8081/api/uploadthing");

try {
url = new URL(initOpts?.url ?? "/api/uploadthing", typeof window.location !== "undefined" ? window.location.origin : process.env.EXPO_PUBLIC_SERVER_ORIGIN ?? `http://${debuggerHost}`);
} catch (err) {
console.warn(`Failed to resolve URL from ${initOpts?.url?.toString()} and ${process.env.EXPO_PUBLIC_SERVER_ORIGIN} or ${debuggerHost}. Your application may not work as expected.`, err);
}
to:
let url = new URL(`${process.env.EXPO_PUBLIC_SERVER_ORIGIN}/api/uploadthing`);
let url = new URL(`${process.env.EXPO_PUBLIC_SERVER_ORIGIN}/api/uploadthing`);
And set the EXPO_PUBLIC_SERVER_ORIGIN variable to my backend's actual URL Am I doing something wrong or is this a bug?
3 Replies
Nate
Nate3mo ago
I don't know if uploadthing has proper support, but if not you may want to put in an issue on their github https://github.com/pingdotgg/uploadthing/issues/new/choose
GitHub
Build software better, together
GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user
Hamza
HamzaOP3mo ago
Yeah I’ll just do an issue and a PR at this point It’s a very simple fix
Hamza
HamzaOP3mo ago
GitHub
[bug]: uploadthing/expo does not read the env vairable correctly ...
Provide environment information It is a monorepo so I ran the command only on the Expo app System: OS: macOS 15.6.1 CPU: (8) arm64 Apple M2 Memory: 454.17 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binari...

Did you find this page helpful?