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
- Websites hosted on my appwrite sites hav...
Hello, all my websites hosted on appwrite sites are not running I am getting this message "This site can’t be reached drivehub.appwrite.network took too long t...
- Can't really use the S3 storage device
hi, I've linked my local MinIO Instance (it's just for testing, not for prod.) to my appwrite instance, when i'm uploading a file it's getting uploaded to the S...
- Quota not resetting
hi, im using appwrite's free tier plani hit my read limts last month and the billing cycle said it would reset on june 4th but that is today, the billing cycle ...