Android Developer
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);
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);
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]