Back

Can't access Images in buckets through url.

  • 0
  • Flutter
  • Storage
  • Cloud
opbaba_
23 Aug, 2024, 09:19

Hi, I'm trying to generate a url for an uploaded image in a bucket using file id.

Even though the user has an active session and read privilege to the image, I'm getting a 401 error saying user is not authorized.

As I understand this is due to credentials aren't being passed in the url and the resource in bucket dosent have read access to all.

Can I pass a JWT as a parameter to access the resource?

Is there any alternative approach I can access the image through a URL? I need to use it in CachedNetworkImage() Widget in flutter

TL;DR
Developers resolved the issue by passing the session secret in headers when the app user wants to access an image. The error was due to credentials not being passed in the URL. An alternative approach could be to pass the JWT as a parameter to access the resource. Use ImageProviders like Image.network() or CachedNetworkImage() in Flutter.
Joshi
23 Aug, 2024, 09:22

When you authenticate a user you get a session object back. Save the session secret for that specific user and when the app user wants to access an image you can pass the secret in the headers.

"x-appwrite-session" : "<session.secret>"

opbaba_
23 Aug, 2024, 09:38

Image.network() or CachedNetworkImage() dosent take headers for the request.

Joshi
23 Aug, 2024, 09:40

They do

Joshi
23 Aug, 2024, 09:41

You have to use the ImageProviders

Joshi
23 Aug, 2024, 09:41

Image(image: NetworkImage("<url>", headers: <headers>)),

opbaba_
23 Aug, 2024, 09:56

Thank you. It worked

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