
Heyo.
Using expo-imagepicker (https://docs.expo.dev/versions/latest/sdk/imagepicker/), I am trying to upload a file to appwrite, however it seems that it keeps saying "undefined" on the console.log(storageData)
. What am I missing?
It also does not upload the image.
Picking the image:
const pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
})
if (!result.canceled) {
const image = result.assets[0]
const maxResolution = 5000 * 5000
const maxFileSize = 8 * 1024 * 1024 // 4MB in bytes
if (image.width * image.height > maxResolution) {
toast('Image resolution is too large')
}
if (image.fileSize > maxFileSize) {
toast('Image file size is too large')
}
if (
image.width * image.height <= maxResolution &&
image.fileSize <= maxFileSize
) {
setImage(image.uri)
setPage(2)
}
}
}
Here's the function:
async function uploadImageAsync() {
if (!image) {
toast('Please select an image to upload')
return
}
if (!title || title.length <= 3) {
toast('Please provide a valid title.')
return
}
try {
//setUploading(true)
const storageData = await storage.createFile(
'gallery',
ID.unique(),
image,
[],
(event) => setProgress(event.progress)
)
console.log(storageData)
await database.createDocument(
'hp_db',
'gallery-images',
storageData.$id,
{
name: title,
longText: description,
nsfw: nsfw,
userId: current.userId,
}
)
} catch (error) {
setUploading(false)
console.error(error)
}
}

Storage file not uploading - React native
Recommended threads
- I had a new error pop up today when test...
I've been working on my app, it worked fine previously but now I recieve Invalid Origin: Register your new client as a new iOS platform on your project console ...
- Realtime didn't work in react native exp...
``` useEffect(() => { const { client } = createClient(); const unsubscribe = client.subscribe(`databases.${process.env.EXPO_PUBLIC_APPWRITE_DATABASE}.t...
- Realtime didn't work in react native exp...
``` useEffect(() => { const { client } = createClient(); const unsubscribe = client.subscribe(`databases.${process.env.EXPO_PUBLIC_APPWRITE_DATABASE}.t...
