Back

storage.createFile() not uploading, get undefined or network request failed

  • 0
  • Android
  • React Native
  • Apple
  • Storage
joey881129
24 May, 2024, 11:25

Hi there, please if anybody can, help me to solve this ridiculous issue.

So, I pick an image file with this code (image 1) it works perfectly by giving back this object:

{"assetId": null, "base64": null, "duration": null, "exif": null, "fileName": "1000021004.jpg", "fileSize": 1733865, "height": 3200, "mimeType": "image/jpeg", "rotation": null, "type": "image", "uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Fdonify-cff8f0d0-4436-4e0c-a7f7-f1ce3e30de03/ImagePicker/1b176a9b-93fb-4645-9a2f-af1dc1932e64.jpeg", "width": 1440}

Then it gets passed on to the uploadFile functun, where it was supposed to be uploaded to my storage in Appwrite (image 2)

The storage.createFile() func doesn't seem to be working. I have stripped my whole code down just to try to upload an image hard-coded, I deleted the mimeType assets and tried just the filepath, I tried to hard-code the name, size, type and uri of the file as well. I always and every time get back the same 'undefined'.

I am also logged in within my app with a user, and gave all the necessary permissions for a file upload.

And then if I try to pick an image with the expo-document-picker, when it gets to uploading it, is gives me promise rejection, Error: AppwriteException: Network request failed.

TL;DR
A developer working on a React Native app encounters an issue with storage.createFile() working only on iOS and receiving "Network request failed" on Android. The fix involves correctly formatting the assets object before passing it to uploadFile(). A user then realizes that the asset might be null due to a missing set, leading to the issue. Finally, using expo-document-picker to upload an image results in a promise rejection with the same error.
D5
24 May, 2024, 11:29

I think asset is null since you have not set it?

D5
24 May, 2024, 11:30

Or at least it's not set in the parts of the code that you sent

joey881129
24 May, 2024, 11:42

It's definitely set. It gives back this object when I log it:

{"assetId": null, "base64": null, "duration": null, "exif": null, "fileName": "1000021004.jpg", "fileSize": 1733865, "height": 3200, "mimeType": "image/jpeg", "rotation": null, "type": "image", "uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Fdonify-cff8f0d0-4436-4e0c-a7f7-f1ce3e30de03/ImagePicker/1b176a9b-93fb-4645-9a2f-af1dc1932e64.jpeg", "width": 1440}

joey881129
24 May, 2024, 11:44

Coming from result.assets[0] and then that's the 'file' argument in the uploadFile(file)

joey881129
24 May, 2024, 11:55

Ahhhh, I've just found a similar topic on here and it solved it. I just had to distribute the assets object to this: { name: asset.name, type: asset.mimeType, size: asset.size, uri: asset.uri }

chrissiku
25 May, 2024, 21:30

I'm working on A reactNative app, when trying to create a new Entry. The bellow code works only on IOS but on Android I have the AppwriteException : Network request failed

TypeScript
export const createEntry = async () => {
  try {
    const newEntry = await databases.createDocument(
      databaseId,
      productCollectionId,
      ID.unique(),
      {
        
      }
    );

    return newEntry;
  } catch (error) {
    throw new Error(error);
  }
};

Having the same error on Android.

The code is working perfectly on IOS but on Android I have the AppwriteException: Nextwork request failed.

if there is any possible fix, please share

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