Skip to content
Init is coming / May 19 - 23
Back

Empty file passed to the endpoint. Expo (Android)

  • 1
  • Android
  • React Native
Mohammed J
2 Dec, 2024, 12:33

Hi Appwrite Team, i am having a issue in android with expo image picker, Below is my code, i pick image from expo image picker, compress it using expo image manipulator, convert it into blob and upload it to appwrite, In web and IOS it completely runs fine but in android only it gives problem, the error i get in console is Network request failed, when i use developer tools for android and i check network tab it shows, The Empty file passed to the endpoint.

The below is the function i use -

const pickImage = async () => { if (imageList.length >= 5) { alert("You can only upload a maximum of 5 images."); return; }

TypeScript
let result = await ImagePicker.launchImageLibraryAsync({
  mediaTypes: ImagePicker.MediaType,
  allowsEditing: true,
  aspect: [4, 3],
  quality: 1,
});

if (!result.canceled) {
  setCompressing(true);
  const imageUri = result.assets[0].uri;

  try {
    // Compress and resize the image
    const compressedImage = await ImageManipulator.manipulateAsync(
      imageUri,
      [{ resize: { width: 500 } }], // Resize width to 500px
      {
        compress: 0.4,
        format: ImageManipulator.SaveFormat.JPEG,
      }
    );

    // Fetch the file as a blob
    const response = await fetch(compressedImage.uri);
    const blob = await response.blob();

    const res = await uploadImageApi(blob);

    // Get the public URL of the uploaded image
    const fileId = res.$id;
    const publicUrl = https://cloud.appwrite.io/v1/storage/buckets/6749c792002950c03a16/files/$%7BfileId%7D/view?project=6749c7010005f7cfffea`;

    if (publicUrl) {
      setImageList((prevImages) => [...prevImages, publicUrl]);
    }
    setCompressing(false);
  } catch (error) {
    setCompressing(false);
    console.error("Error uploading image:", error);
  }
}

};`

TL;DR
Issue reported when uploading images in android using Expo Image Picker. Error message 'Network request failed' with 'The Empty file passed to the endpoint' in Android only. Code provided to pick image, compress, convert to blob, and upload to Appwrite. Works in web and iOS. Potential Solution: Check the image compression and conversion process on Android to ensure the file is not being passed as empty.
Mohammed J
3 Dec, 2024, 05:36

Any updates @Appwrite team ?

D5
3 Dec, 2024, 11:03

What error do you get?

D5
3 Dec, 2024, 11:03

You can't upload multiple images at once

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more