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:
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
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;
Recommended threads
- All My Project is Gone
Hello everyone, please help. Why have all my projects suddenly disappeared? I received a warning via email about one of my projects being paused. When I clicked...
- Appwrite for Education
I am writing to report an issue with my account limits. I currently have the GitHub Student Developer Pack active, which should include 10 Appwrite Pro projects...
- How to stop my project from being frozen...
So we encountered an error in production because our appwrite project had been frozen due to inactivity. Is there any way of automating checking in and activity