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
- Deep Linking & Password reset
I am using react native with expo. I want to implement deep link with the url recived via email. So when clicked the link it opens my app. I havent ever used de...
- Need Help with Google OAuth2 in Expo usi...
I'm learning React Native with Expo and trying to set up Google OAuth2 with Appwrite. I couldn't find any good docs or tutorials for this and my own attempt did...
- [SOLVED] React Native Appwrite SDK not w...
So I'm trying to generate a unique ID using the ID.unique() and its generating properly, but its saying its longer than 36 characters but it isnt.. ```typescri...