Back

[AppwriteException: Network request failed]

  • 0
  • Android
  • Storage
pratham
12 Jun, 2024, 19:56

i am trying to upload file from my mobile device to storage appwrite using react native but still i am not bale to do so..

(Aslo i am running my laptop and mobile on same network ) and my appwrite storage code import { Client, ID, Storage } from "react-native-appwrite"; const client = new Client(); client .setEndpoint("https://cloud.appwrite.io/v1") .setProject("665ee812000a06336853"); const storage = new Storage(client); const uploadImage = async (image) => { try { console.log('Uploading image:', image.name) const response = await fetch(image.uri); console.log('Fetch response status:', response.status);

const blob = await response.blob(); console.log('Blob size:', blob.size);

TypeScript
const file = new File([blob], image.name, {
  type: blob.type,
});
console.log('File created:', file);

const result = await storage.createFile(
  '66673d8a0009ad6cccb7',
  ID.unique(),
  file
);
console.log('File uploaded:', result);

return result.$id;

} catch (error) { console.error('Error uploading image:', error); throw error; } };

export const uploadImages = async (images) => { try { console.log('Uploading images:', images.length);

TypeScript
const fileIds = await Promise.all(images.map(uploadImage));
console.log('Uploaded file IDs:', fileIds);

return fileIds;

} catch (error) { console.error('Error uploading images:', error); throw error; } }; and my output is LOG Uploading images: 1 LOG Uploading image: 1000135179.jpg LOG Fetch response status: 200 LOG Blob size: 97953 LOG File created: {"_data": {"__collector": {}, "blobId": "c79ada6f-f8e9-42bc-80d8-d2dace6ed1d9", "lastModified": undefined, "name": "1000135179.jpg", "offset": 0, "size": 97953, "type": "image/jpeg"}} ERROR Error uploading image: [AppwriteException: Network request failed] ERROR Error uploading images: [AppwriteException: Network request failed] ERROR [AppwriteException: Network request failed]

TL;DR
Developers are facing an issue uploading files to Appwrite storage using React Native, receiving a "Network request failed" error. Ensure the mobile and laptop are on the same network. The issue might be with the network configuration or authorization for the API request.
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