Back

[Appwrite exception:Network Request Failed]

  • 0
  • Android
  • React Native
  • Cloud
hemant_rajput
31 Aug, 2024, 03:50

async uploadProfilePicture(fileUri: string, phoneNumber: string) { try { // Get the file extension and use it to create the file name const fileType = fileUri.split('.').pop(); const fileName = ${phoneNumber}.${fileType};

TypeScript
    // Fetch the file data from the URI
    const response = await fetch(fileUri);
    if (!response.ok) {
        throw new Error('Failed to fetch the image file.');
    }

    const fileBlob = await response.blob();

    // Create a new File object without explicitly setting the MIME type
    const file = await storage.createFile(
        '66d17e5b0023edd74cde', // Replace with your bucket ID
        ID.unique(),
        new File([fileBlob], fileName)
    );

    return file; // Returns the file metadata
} catch (error: any) {
    console.error('Error uploading profile picture:', error);

    if (error.message.includes('Network request failed')) {
        Alert.alert('Network Error', 'Please check your internet connection and try again.');
    } else {
        Alert.alert('Upload Error', 'There was an error uploading your profile picture. Please try again.');
    }

    throw error; // Rethrow the error after handling it
}

} This is showing following error [Appwrite exception:Network Request Failed] Please help

TL;DR
The developers are experiencing a "Network Request Failed" exception in their Appwrite app. The issue is occurring during the uploadProfilePicture function. The error is being caught and handled with an alert message based on the error type. The solution suggests checking the internet connection and trying again if a network error is detected.
hemant_rajput
31 Aug, 2024, 03:53

[Appwrite exception:Network Request Failed]

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