
Hi, I'm new to appwrite so it can be obvious mistake but I'm stuck and don't know how to move on :/
Here is my problem: I'm making an app in react native. I want to change profile image by deleting old one from storage and upload newest image. Everything is working fine on web browser, but when I'm trying to do it on my ios the created file has size 0 and mimeType application/x-empty. Before creating file I'm checking the size and type of chosen image and it's all good.
Here are my fragments of code to do so:
- conventer uri to file "" const uriToFile = async (uri, fileName, imageType) => { const response = await fetch(uri); const blob = await response.blob(); console.log('Blob type: ', blob.type); const file = new File([blob], fileName, { type: imageType }); return file; };
""
"" const updateProfilePicture = async (userId, oldFileId, newFileUri, documentId, imageType) => { try { // Delete
await storage.deleteFile('66a0fb33002ea2c56095', oldFileId);
console.log("File deleted successfully.");
// Upload
const newFile = await uriToFile(newFileUri, userId, imageType);
const newFileUploaded = await storage.createFile(
'66a0fb33002ea2c56095',
ID.unique(),
newFile
);
console.log('Uploaded');
console.log('New file: ', newFile);
console.log('NewFile-size: ', newFile.size);
console.log('New file type: ', newFile.type);
console.log('After createFile(): ', newFileUploaded);
// Update id
await databases.updateDocument(
'669a22000039eeadb976',
'66a0fb5b001f6434e99a',
documentId,
{ image_id: newFileUploaded.$id }
);
console.log('Image Id: ', newFileUploaded.$id);
console.log("Updated");
console.log('Profile picture updated successfully!');
} catch (error) {
console.error('Error updating profile picture:', error);
}
}; "" I will appreciate any help 🙂

Here are also my console logs: "" LOG Uri of new image: file:///var/mobile/Containers/Data/Application/4E1A122C-7196-46B1-BC00-F0EC39DE2990/Library/Caches/ExponentExperienceData/@anonymous/cytrynka-e449390d-4def-455f-a51a-25d143c301ad/ImagePicker/7383A1B8-BF63-49DF-AC1E-C78A8622006D.png LOG Name of new image: IMG_4848.png LOG MimeType of new image: image/png LOG File deleted successfully. LOG File-size: 140563 LOG Uploaded LOG New file: {"_data": {"__collector": {}, "blobId": "88983c4d-6d8d-40c0-a6af-678939988ded", "lastModified": undefined, "name": "6699130f0025813268c7", "offset": 0, "size": 140563, "type": "image/png"}} LOG NewFile-size: 140563 LOG New file type: image/png LOG After createFile(): {"$createdAt": "2024-08-02T13:11:26.079+00:00", "$id": "66acdafd001ee32264dc", "$permissions": ["read(user:6699130f0025813268c7)", "update(user:6699130f0025813268c7)", "delete(user:6699130f0025813268c7)"], "$updatedAt": "2024-08-02T13:11:26.079+00:00", "bucketId": "66a0fb33002ea2c56095", "chunksTotal": 1, "chunksUploaded": 1, "mimeType": "application/x-empty", "name": "6699130f0025813268c7", "signature": "d41d8cd98f00b204e9800998ecf8427e", "sizeOriginal": 0} LOG Image Id: 66acdafd001ee32264dc LOG Updated LOG Profile picture updated successfully! ""

And the way how I'm getting an image: "" const changeProfileImage = async () => { let permissionResult = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (permissionResult.granted === false) {
Alert.alert("Permission to access camera roll is required!");
return;
}
let pickerResult = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
});
if (!pickerResult.canceled) {
const newImageUri = pickerResult.assets[0].uri;
const newImageFileName = pickerResult.assets[0].fileName;
const newImageType = pickerResult.assets[0].mimeType;
console.log("Uri of new image: ", newImageUri);
console.log("Name of new image: ", newImageFileName);
console.log("MimeType of new image: ", newImageType);
const user = await account.get("current");
const userProfile = profileData.find(profile => profile.user_id === user.$id);
// userProfile is for get correct Id of image for current user from my collection
if (userProfile) {
await updateProfilePicture(user.$id, userProfile.image_id, newImageUri, userProfile.$id, newImageType);
setProfileImage(newImageUri);
}
}
}; ""
Recommended threads
- [AppwriteException: Network request fail...
When I tried to list the documents from one of the collections, it would show Error: Network request failed. But if I tried others, it would show all of the doc...
- Question about adding duplicate worker-f...
1.) Is this still this is a valid strategy for having parallel processing of async function executions? I saw some support threads on the appwrite site which we...
- Need help on Flutter OAuth2
Am trying to use Appwrite OAuth (google, apple and facebook), am been on it for sometimes now which have tried many things but still not able to make it work: ...
