Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Feature: getURLToFile #23

Open
2 tasks done
Tracked by #557
davilico05 opened this issue Sep 22, 2022 · 7 comments
Open
2 tasks done
Tracked by #557

🚀 Feature: getURLToFile #23

davilico05 opened this issue Sep 22, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@davilico05
Copy link

🔖 Feature description

I'm playing with appWrite for a personal project. I've using appwrite database and storage.

All great until trying to use AVPlayer...
We need an url to load the video and I have ByteBuffer from SwiftNIO 🫠

It would be great to have and url way to access file.

¿Already it exist any way to load a video from existing getFileView into AVPlayer? ¿Anyone can help me?

Sorry if it is a unnecessary issue on GitHub

🎤 Pitch

Other SDKs like VimeoSDK give you an url with special token of the file requested

appWrite URL: https://127.0.0.1/v1/storage/buckets/123/files/123/view?project=123
Vimeo URL: https://127.0.0.1/v1/storage/buckets/123/files/123/view?project=123&token=123

That token include security directives, role, etc. That way allow us (developers) to use the URL for AVPlayer for example without conversions and keep the streaming file (I think they use HLS for video file instead of byte ranges)

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@ftp27
Copy link

ftp27 commented Oct 30, 2022

I had the same issue a week ago. But I had short videos in my case, so the solution was saving files to the cache directory and playing them locally. Maybe it'll work for you too.

@davilico05
Copy link
Author

It's a good point. However, in my case I have a large video files so I need stream file functionality.
Thanks anyway

@stnguyen90
Copy link
Contributor

@davilico05, does the way you're using the URL allow you to pass headers? If so, you can use account.createJWT() and then pass that in the X-Appwrite-JWT header.

@ftp27
Copy link

ftp27 commented Oct 30, 2022

So we need to make something like

let path = "/storage/buckets/\(bucketId)/files/\(fileId)/view"
let headers: [String: Any] = ["x-appwrite-project": projectId]
let url = URL(string: endPoint + path)!
let asset = AVURLAsset(url: url, options: ["AVURLAssetHTTPHeaderFieldsKey": headers])

I think it's would be better to have access to client field at least. So we can make an extension for Storage which will return AVURLAsset.

@stnguyen90
Copy link
Contributor

@ftp27, you're missing the JWT token as mentioned here: #23 (comment).

I've proposed a change to the SDKs to generate the url so you don't need to do:

let path = "/storage/buckets/\(bucketId)/files/\(fileId)/view"
let headers: [String: Any] = ["x-appwrite-project": projectId]
let url = URL(string: endPoint + path)!

That issue is here: appwrite/sdk-generator#557

But you would still need to create the JWT token.

@ftp27
Copy link

ftp27 commented Oct 30, 2022

I don't need it in my case, so I can't check the "solution" with JWT. When I'm trying to make a token I receive a message with something about the configuration of my dashboard :)

@stnguyen90
Copy link
Contributor

I don't need it in my case, so I can't check the "solution" with JWT.

Ah, if you're file is public then there's no need to create and include a JWT token.

When I'm trying to make a token I receive a message with something about the configuration of my dashboard :)

Interesting...maybe you disabled JWT tokens. No worries though if you don't need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants