This is an Ionic Capacitor App and I believe the issue is that the API call is being made from the device. The same code works correctly when running from web/local host.
Everything else works fine, the images are uploaded properly, I can authenticate and retrieve documents, it is just when using the preview URL that is returned I get the 401 Error
Is this a configuration issue? Do I need to set the hostnames value in the project configuration?
I am currently out of ideas, Thanks In Advance
Summary
Issue: Getting a 401 Error when attempting to preview images from the cloud, specifically on iOS devices. The code works fine on web/local host.
Solution: The issue seems to be with cookies not being sent in the network request for the image. Two possible solutions are suggested:
1. Grant any user read access to the bucket.
2. Generate a JWT token and include it in the headers of the network request.
Additional Details:
- There is a discussion on GitHub about capacitor iOS cookies that may provide more insights.
- The SDK for Web uses cookies for session management, but some runtime environments may cause problems.
- The issue is only
Drake
Admin
May 1, 2023, 19:47
the SDK for Web uses cookies for session management. Typically, the cookie is sent automatically, but in some cases 3rd party cookies or some other runtime environments can cause problems.
In those cases, you might need to generate a JWT token and include that in the headers of the network request
aaronksaunders
Rank 2: Process
May 1, 2023, 19:48
that is interesting because it works fine with Android...
since i ma using the javascript API, I would need to generate the toke and pass it with the URL that was returned from the getPreview call?
aaronksaunders
Rank 2: Process
May 1, 2023, 19:49
i read all that already, but that did seemed to be discussing auth
Drake
Admin
May 1, 2023, 19:49
yes...this is an auth problem...
aaronksaunders
Rank 2: Process
May 1, 2023, 19:49
the rest of the application works fine... it is only when i try to rended the preview url
Drake
Admin
May 1, 2023, 19:51
are you rendering any other images using storage.getFileView() or storage.getFileDownload()?
aaronksaunders
Rank 2: Process
May 1, 2023, 19:51
i was about to switch to the FileDownload call to see if i get different results
Drake
Admin
May 1, 2023, 19:52
go ahead. You'll probably get the same error. Then, you can try to grant any user read access to your bucket and try again
aaronksaunders
Rank 2: Process
May 1, 2023, 19:52
i believe it is the client hostname is getting rejected by the server when i request using the url
Drake
Admin
May 1, 2023, 19:53
we don't return a 401 for origin validation
Drake
Admin
May 1, 2023, 19:53
Please try with bucket read permissions set to any
aaronksaunders
Rank 2: Process
May 1, 2023, 19:54
setting it to any works
Drake
Admin
May 1, 2023, 19:55
right so it's an access problem because the cookie is not being sent in the network request for the image
aaronksaunders
Rank 2: Process
May 1, 2023, 19:55
hmm.... i would like to find a better solution
Drake
Admin
May 1, 2023, 19:56
if you want to go down the cookie route, you'll need to find out what's wrong with capacitor and the cookies. otherwise, you can try to see how to pass a JWT token in the header when fetching the image...although im not sure how to do that using capacitor
aaronksaunders
Rank 2: Process
May 1, 2023, 19:56
i am passing the url to an image tag... not sure how i would be able to provide a token?
aaronksaunders
Rank 2: Process
May 1, 2023, 19:59
thanks
Drake
Admin
May 1, 2023, 20:00
right...maybe capacitor exposes some special way to pass headers? 🤷🏼♂️
ideally, if you get cookies to work, it would work automatically
aaronksaunders
Rank 2: Process
May 1, 2023, 20:29
Leaving this here for anyone else who comes across this problem. I solved it by modifying my capacitor.config.ts