Back

React Native Expo file upload - no error, no file

  • 0
  • Self Hosted
  • React Native
RetroNoodle
16 Nov, 2024, 15:35

Here is my code:

TypeScript
const uploadImage = async (uri) => {
    try {
      console.log("Uploading file from URI:", uri);

      const fileId = ID.unique();
      console.log("Uploading file with ID:", fileId);
      const uploadedFile = await storage.createFile(
        APPWRITE_BUCKET_ID,
        fileId,
        uri
      );
      console.log("Uploaded file:", uri);
      return fileId;
    } catch (error) {
      console.error("Error in uploadImage:", error);
      throw new Error("Failed to upload image: " + error.message);
    }
   
  };

So that catch never fires, it returns the fileId to the calling function, as if everything worked, but no file shows in the console.

I'm using the react-native specific appwrite libs.

TL;DR
Developers are having trouble with uploading a file using React Native Expo, receiving no error but not finding the uploaded file. The log errors appear to be unrelated. The issue might be that the code is returning the fileId without confirming the file upload. To solve this, check if the file is successfully uploaded after calling `storage.createFile()` before returning the fileId.
RetroNoodle
16 Nov, 2024, 15:35

The errors in the log are confusing:

TypeScript
Failed to initialize logging provider: Unable to parse DSN: scheme is required
[Error] Timestamp: 2024-11-16T15:30:28+00:00
[Error] Method: 
[Error] URL: /sitemap.xml
[Error] Type: Appwrite\Extend\Exception
[Error] Message: The requested route was not found. Please refer to the API docs and try again.
[Error] File: /usr/src/code/app/controllers/general.php
[Error] Line: 1051
Failed to initialize logging provider: Unable to parse DSN: scheme is required
[Error] Timestamp: 2024-11-16T15:30:31+00:00
[Error] Method: 
[Error] URL: /config.json
[Error] Type: Appwrite\Extend\Exception
[Error] Message: The requested route was not found. Please refer to the API docs and try again.
[Error] File: /usr/src/code/app/controllers/general.php
[Error] Line: 1051
Failed to initialize logging provider: Unable to parse DSN: scheme is required
[Error] Timestamp: 2024-11-16T15:30:32+00:00
[Error] Method: GET
[Error] URL: /v1/storage/buckets/:bucketId/files/:fileId
[Error] Type: Appwrite\Extend\Exception
[Error] Message: The requested file could not be found.
[Error] File: /usr/src/code/app/controllers/api/storage.php
[Error] Line: 819
Failed to initialize logging provider: Unable to parse DSN: scheme is required

I'm not sure what the first two are, and the last one is a GET, which wouldn't reflect what I am doing above. Maybe it tries to get the file after upload and its not there?

D5
16 Nov, 2024, 15:38

Are you sure that the file ID and bucket ID is correct?

RetroNoodle
16 Nov, 2024, 15:43

Well, the bucket ID yes, the fileId I assume is somthing I am setting and sending with it

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