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 🙂