
Hey, I have been stuck on this issue for 2 days trying every approach but I couldn't solve it alone. I am unable to upload photos to my appwrite storage. Here's the function that handles uploading:
TypeScript
export async function uploadFile(file, type) {
if (!file) return;
const { mimeType, ...rest } = file;
const asset = { type: mimeType, ...rest };
try {
const uploadedFile = await storage.createFile(
appwriteConfig.storageId,
ID.unique(),
asset
);
const fileUrl = await getFilePreview(uploadedFile.$id, type);
return fileUrl;
} catch (error) {
throw new Error(error);
}
}
and here's the function that handles getting the photo from the user
TypeScript
import React, { useState } from "react";
import * as ImagePicker from "expo-image-picker";
import { Alert } from "react-native";
const PhotoPicker = () => {
const [photo, setPhoto] = useState(null);
const pickImage = async () => {
try {
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
});
if (!result.cancelled) {
setPhoto(result.assets[0]);
} else {
console.log("Image selection cancelled");
}
} catch (error) {
console.error("Error picking image:", error);
Alert.alert("Error", "Failed to pick image. Please try again.");
}
};
return { photo, pickImage };
};
export default PhotoPicker;
TL;DR
Developers are having trouble with the `react native storage.createFile` function not working for uploading photos to an appwrite storage. The code snippets provided show a function for uploading files and a component for getting a photo from the user. The issue seems to be related to the `storage.createFile` method not functioning correctly for uploading photos. Further debugging and testing of the `uploadFile` function are recommended to identify and resolve the problem.Recommended threads
- Storage & Database is not allowing.
Storage & Database is not allowing to CRUD after i have logged in ? Using web SDK with next.js without any SSR or node-sdk.
- Privacy settings for storage
In my app the user could upload sensitive images for themselves (as a weight loss journal) and they probably don’t want developers or anyone else but themselves...
- Corrupted files on AWS S3
Hello! I'm having trouble using S3 storage with appwrite for file uploads. It happens when uploading files from the Javascript SDK or from the console. The fi...
