[Expo + UT] Error when importing @uploadthing/expo
Hey, I am building an expo app and I am getting this error when importing the package (only on native, web works fine)
SDK versions:
Attaching my stacktrace from sentry (raw and a screenshot).
I looked at the SDK source and found that the only place where
TextDecoder
is used is packages/uploadthing/src/internal/shared-schemas.ts
Help appreciated 🙂27 Replies
I think RN doesn’t have TextDecoder natively, you need to polyfill it eg
expo install @bacons/text-decoder
Cc @julius - RN + effect might be somewhat problematicexpo 52 will have text-decoder ootb but until then you just need a polyfill
there is an issue though which i've half fixed here: https://github.com/pingdotgg/uploadthing/pull/1013 but still not entiery fixed. my guess it's RNs weird blob implementation
GitHub
fix:
@uploadthing/mime-types
exports not supported in Expo by jul...Closes #999
flatten export paths since Expo doesn't resolve exports condition by default. This is similar to what we do for the main uploadthing package which has multiple entrypoints as w...
They’re using the canary from that PR
I was able to get it to not error out using a polyfill (
text-encoding-polyfill
). But then my uploads are failing with
This error may or may not be related
The SDK does not even call my /api/uploadthing endpoint. However, the same setup works fine on the web export of the appCan you get the error.cause when it fails with that error?
That was a false alarm, I did not setup port forwarding correctly on my device - the host wasn't found hence no requests.
But now I am getting the error "UPLOAD_FAILED" (code and message is the same) with undefined err.cause. The upload action to my /api/uploadthing API resolves to a 200 response so I am assuming it is failing to upload to the signed URL.
(trying to confirm this assumption)
Can you enable debug logs on the server side to see where it is getting hung up on more detail?
I’ll take a look and revive the PR later today. Last time I tried it everything seemingly worked except no bytes were uploaded to UT (file said uploaded and 0B on the dash)
Okay so I did some digging and here is what's happening:
1. My /api/uploadthing api resolves with the correct presigned url
2. UT sdk makes a HEAD request to the signed URL which succeeds (which is 0B in size)
3. SDK errors out with the error I shared earlier ("UPLOAD_FAILED"). It never sends the PUT/POST request with the actual file.
Here is the signed URL: https://sea1.ingest.uploadthing.com/VeWg9249ETbUVe0a0y49ETbU4LmjuWZpgvsiNy20cadl56Io?expires=1730807221847&x-ut-identifier=72uz6xz82c&x-ut-file-name=047f9be7-7e94-4e95-9008-f12e5fb3d9bd.jpeg&x-ut-file-size=243608&x-ut-file-type=image%2Fjpeg&x-ut-slug=videoAndImage&x-ut-custom-id=wf9i4suwqj5b4hkvxkule5x5w6jg&x-ut-content-disposition=inline&x-ut-acl=public-read&signature=hmac-sha256=24f46a6c19b09d606e63aff002f29376ec47d165c9658a1315eb3e93131ebf10
just got home from school will start to investigate this now
🙌
@sudhanshug this is how our example works from the PR that fixes the mime-type exports resolution
no errors, just doesn't get any data. what are you doing to make it error?
Can you try jsdebugger’s network tab and see if your upload request resolves. I only see a HEAD request
yea it's sending the PUT
looks empty for sure 😦
problem definetely feels like it's due to RNs stupid blob implementation not being sliceable
npm
react-native-blob-util
A module provides upload, download, and files access API. Supports file stream read/write for process large files.. Latest version: 0.19.11, last published: 3 months ago. Start using react-native-blob-util in your project by running
npm i react-native-blob-util
. There are 65 other projects in the npm registry using react-native-blob-util.looking at that now
there's like 3 levels of forks to have a maintained one though 😅
i wrote this a few days ago to do direct uploads to s3 via activestorage
maybe it's of use to you lol, maybe not
i have it working without resumability
can you cut me an adhoc build lol, my users are kinda stuck 🙃
good for me, they are our contractors and I can direct them to the web app
but not ideal 🙂
building
pnpm add @uploadthing/[email protected] [email protected]
Hello, Im having the same issue
TextDecode
How to fix it?
btw in installed the above canary versionthis is what im getting when api route triggered
Expo 52 should have both encoder and decoder built-in but before then you need to use a polyfill.
what version of expo/expo-image-picker?