π Feature: getURLToFile
davilico05 opened this issue Β· 7 comments
π 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?
- I have read the Code of Conduct
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.
It's a good point. However, in my case I have a large video files so I need stream file functionality.
Thanks anyway
@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.
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.
@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.
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 :)
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.