
I was trying to store my images in appwrite storage but got encountered with this error , i have use expo-image-picker to pick image from gallery in react native . please help me with this it is showing "Network Request failed"

Could you please send the code you're using to store/send the images to appwrite and the image picker code?

const uploadToAppwrite = async (uri) => { try { const response = await fetch(uri); const blob = await response.blob();
const file = new File([blob], 'image.jpg', { type: 'image/jpeg' });
console.log("FILE ",file);
// Upload the file to Appwrite storage
const promise = storageApi.uploadFile(file);
promise.then(function (response) {
console.log("Create Success ==> ", response);
}, function (error) {
console.log("Create Error ==> ", error);
})
} catch (error) {
console.log('Error uploading file to Appwrite:', error);
}
};

import appwriteConfig, { storage } from "./appwriteConfig"; import { ID } from "appwrite";
const boatImageBucketId = appwriteConfig.Storage_BoatImageID;
let storageApi = {
getFile: (fileId) => { const result = storage.getFilePreview(boatImageBucketId, fileId); return result.href; },
deleteFile: (fileId) => { const promise = storage.deleteFile(boatImageBucketId, fileId); return promise; },
listFiles: () => {
return storage.listFiles(boatImageBucketId);
},
uploadFile: (File) => { return storage.createFile(boatImageBucketId, ID.unique(), File); }, };
export default storageApi;

react and react native handles files differently

this is how i do it
const formData = new FormData();
formData.append("fileId", fileIdP);
formData.append("file", {
uri: uri,
name: filename,
type,
});
const response = await fetch(
`${appwrite.config.endpoint}/storage/buckets/${bucketId}/files`,
{
method: "POST", // or 'PUT'
headers: {
...appwrite.headers,
"Content-Type": "multipart/form-data;",
},
body: formData,
}
);
return response.json();
Recommended threads
- android kotlin error updatePhone
package vasu.apps.schooldashboard.Services import android.util.Log import io.appwrite.Client import io.appwrite.ID import io.appwrite.exceptions.AppwriteExcept...
- Google OAuth2 screen loop issue in Flut...
i am trying to authenticate user on my app using google, everything works fine, but even after succesfull authentication instead of redirecting back to the app,...
- getting network issue when trying to acc...
