Back

How to update array of images ? (Its always ampty)

  • 0
  • Web
A
20 Nov, 2023, 11:39
TL;DR
The user is trying to update an array of images, but the array is always empty in the appwrite database, even though the JSON data contains the array of images. There are no errors reported. To solve this issue, you can check the following: - Make sure the `updateGalaryScroll()` function is properly implemented and called. - Check if the `val.photos` array is being populated correctly after uploading the images. Uncomment the lines `// if (val.photos != undefined)` and `// val?.photos = imageView.href` if necessary. - Verify that the `filteredVals` array is correctly formed before calling the `api
Haimantika
20 Nov, 2023, 13:29

Can you show the code?

A
20 Nov, 2023, 15:05

yeah

A
20 Nov, 2023, 15:06

const { mutate: updateData, reset, } = useMutation({ mutationFn: async (newGalData: GalaryScrollBlock | null | undefined) => { console.log(newGalData) if (newGalData) { // console.log(newGalData) const dataId = newGalData.map((item) => { return item.$id })

TypeScript
    const filteredVals = newGalData.map((item) => {

      // console.log(itemPhoto)
      const newData: any = {
        mainPhoto: item.mainPhoto,
        photos: item.photos,//item.photos
        // photos: 
        price: Number(item.price),
        features: item.features,
        description: item.description || '',
        status: item.status,
        location: item.location
      }
      return newData
    })
    console.log(filteredVals)
    // Promise.all(filteredVals.map())
    filteredVals.map((item, i) => { return api.updateGalaryScroll(filteredVals[i], dataId[i]) })
    // .then(alert);
    // console.log(filteredVals)

  }

},
onSuccess: () => {
  alert('Success')
  setTimeout(reset, 2000)
},
onError: (error) => {
  console.log(error)
}

})

A
20 Nov, 2023, 15:06

val.posterPhotos.map(async (valImageFile: File, i: number) => { const fileId = magazinesScroll-image-${i}-${hash} console.log(val) await api .uploadGalaryImage(fileId, valImageFile) .then((res) => { const imageView = api.sdk.storage.getFileView(api.galaryImagesBucket, fileId) console.log(val) // delete val.photos // if (val.photos != undefined) {

TypeScript
                  // imageView.href
                  // val!.photos = imageView.href
                  // }
                  // val?.photos = imageView.href
                  val?.photos.push(imageView.href)
                })
                .catch((err) => {
                  hasErrors = true
                  form.setFieldError(`data.${i}.posterFile`, err.message)
                })
                .finally(() => {
                  setPostersUploadingId(-1)
                  delete val.posterPhotos
                })
            })
A
20 Nov, 2023, 15:08
A
20 Nov, 2023, 15:08
Drake
20 Nov, 2023, 20:01

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

Drake
20 Nov, 2023, 20:06

Please share the code for updateGalaryScroll()

A
27 Nov, 2023, 04:24
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more