Back

[SOLVED] Update Image File to Storage

  • 1
  • Android
  • Storage
joeyouss
20 Jun, 2023, 13:09

When you say update, you mean you want to change the image or perform actions and then update?

TL;DR
The user was initially having trouble updating an image file to storage, but they have solved the issue. They were able to get the file id from the response of creating the file, and they are wondering how to save it in the preferences. It was mentioned that the function `createFile()` works correctly and generates a unique ID server-side. However, there seems to be confusion around a piece of code that always returns the same string. The user is trying to save the new file id in the user's preferences but is advised not to do so due to caching. There is a suggestion to upload a new image with a new ID instead of
retr122
20 Jun, 2023, 13:25

change the image

retr122
20 Jun, 2023, 13:25

this is function that change user's logo image

joeyouss
20 Jun, 2023, 13:55

amm, you cannot actually make changes, you can upload a new image, and use new ID. This approach helps with 0 downtime during image update.

retr122
20 Jun, 2023, 14:23

I'll try it and post it later

retr122
22 Jun, 2023, 10:21

I tried it but...

retr122
22 Jun, 2023, 10:21

New picture is successfully downloaded to the Storage

retr122
22 Jun, 2023, 10:22

but when i getFilePreview this shows me past picture

retr122
22 Jun, 2023, 10:22

maybe I'll wait a few minutes or this is error here?

joeyouss
22 Jun, 2023, 13:18

did you try again now?

Drake
22 Jun, 2023, 17:01

did you re-use the same ID?

retr122
22 Jun, 2023, 17:02

Yes

Drake
22 Jun, 2023, 17:04

i highly advise against this due to caching.

retr122
22 Jun, 2023, 17:05

I have one idea, i'll try it and report later

retr122
23 Jun, 2023, 14:03

i'm trying to save new file id in user's prefs but

retr122
23 Jun, 2023, 14:03

This code ALWAYS returns unique() string

retr122
23 Jun, 2023, 14:04

String newAvatarFileId = (String) ID.Companion.unique();

retr122
23 Jun, 2023, 14:04

Why this code isn't generate random id string?

retr122
23 Jun, 2023, 14:07

P.S but

retr122
23 Jun, 2023, 14:08

in this code works correct only createFile() function

Drake
23 Jun, 2023, 14:54

because that's what the function does: https://github.com/appwrite/sdk-for-android/blob/10cc15d7546e9dae5eb131c77270b5d89c82d894/library/src/main/java/io/appwrite/ID.kt#L8

The server detects "unique()" and generates a unique ID server-side

retr122
23 Jun, 2023, 15:02

how to catch this value and save in the prefs?

Drake
23 Jun, 2023, 15:13

Get the file id from the response of create file

retr122
23 Jun, 2023, 15:51

Thanks, it FINALLY works!

Drake
23 Jun, 2023, 16:01

[SOLVED] Update Image File to Storage

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