Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(@uploadthing/expo): uploading File objects results in 0 bytes uploaded #1057

Open
1 of 2 tasks
mandrillxx opened this issue Nov 18, 2024 · 2 comments
Open
1 of 2 tasks
Labels
area:packages issue regarding one of the uploadthing packages bug: low priority something isn't working as it should, but it's not critical to the core functionality workaround available solution exists for the issue using existing functionality, although it may not be optimized for DX

Comments

@mandrillxx
Copy link

Provide environment information

System:
    OS: Windows 11 10.0.22631
    CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900K
    Memory: 36.18 GB / 63.75 GB
  Binaries:
    Node: 20.11.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.12.2 - C:\Program Files\nodejs\pnpm.CMD
    bun: 1.1.30 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    typescript: ^5.3.3 => 5.3.3

Describe the bug

manually uploading a file by getting the media path, reading it as base64 and converting to a file to use with uploadthing will produce an image with the size NaNundefined

Link to reproduction

N/A

To reproduce

// upload.ts
import type { OurFileRouter } from "@garange/upload/core";
import { generateReactNativeHelpers } from "@uploadthing/expo";

export const { useImageUploader, createUpload, uploadFiles, useUploadThing } =
  generateReactNativeHelpers<OurFileRouter>({
    url: `${process.env.EXPO_PUBLIC_API_URL}/api/upload`,
  });
// app/vision.tsx
import * as FileSystem from "expo-file-system";

export default function CameraVision() {
  const { startUpload } = useUploadThing("resellerUploader", {
    onClientUploadComplete: (res) =>
      Alert.alert("Uploaded", JSON.stringify(res)),
    onUploadError: (error) => Alert.alert("Error", error.message),
  });

  async function onMediaCaptured(media: PhotoFile) {
    const fileData = await FileSystem.readAsStringAsync(media.path, {
      encoding: FileSystem.EncodingType.Base64,
    });
    const file = new File([fileData], "image.jpg", { type: "image/jpeg" });
    const upload = await startUpload([file]);
  }
}

Additional information

The above code will upload, and by doing a conosle.log of the fileData object it shows this, which looks correct:
{
"_data": {
"blobId": "3f07ab59-e857-4e53-a8ea-cfb7b356b31e",
"offset": 0,
"size": 346348,
"type": "image/jpeg",
"__collector": {},
"name": "image.jpg"
}
}

also, the alert inside onClientUploadComplete does show the size as 346348, however the image shows up like this https://utfs.io/f/L1LEbSwZ6Eu7mwXSfb15iPMagyczdEQsHt9nKIZGR6m7AhFo with a size of NaNundefined

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR fixing this bug!

Code of Conduct

  • I agree to follow this project's Code of Conduct
@mandrillxx mandrillxx added area:packages issue regarding one of the uploadthing packages 🐛 bug: unconfirmed labels Nov 18, 2024
@juliusmarminge
Copy link
Collaborator

we have to do some weird workarounds to get RN blobs to behave. See here for example: https://github.com/pingdotgg/uploadthing/blob/main/packages/expo/src/image-picker.ts#L98-L113

We should "overload" the useUploadThing hook that's returned from generateReactNativeHelpers since currently that's forwarded straight from @uploadthing/react web package

@mandrillxx
Copy link
Author

we have to do some weird workarounds to get RN blobs to behave. See here for example: https://github.com/pingdotgg/uploadthing/blob/main/packages/expo/src/image-picker.ts#L98-L113

We should "overload" the useUploadThing hook that's returned from generateReactNativeHelpers since currently that's forwarded straight from @uploadthing/react web package

this fixed it, thanks

@juliusmarminge juliusmarminge added bug: low priority something isn't working as it should, but it's not critical to the core functionality workaround available solution exists for the issue using existing functionality, although it may not be optimized for DX and removed 🐛 bug: unconfirmed labels Nov 19, 2024
@juliusmarminge juliusmarminge changed the title [bug]: @uploadthing/expo@^7.1.1 Manually uploaded image has NaNundefined size when uploaded bug(@uploadthing/expo): uploading File objects results in 0 bytes uploaded Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:packages issue regarding one of the uploadthing packages bug: low priority something isn't working as it should, but it's not critical to the core functionality workaround available solution exists for the issue using existing functionality, although it may not be optimized for DX
Projects
None yet
Development

No branches or pull requests

2 participants