0

I would like to create a function that gets the data in my firebase cloud storage. For example, I have 3 separate folders as follows: Movies, Songs and previews. I would like to create a function that will be able to download the url file of the specified folder to get the data of it so I can display it on the selection screen. I have the folders pretty organized. They're in this order, Movies/MovieName/{Movie.jpg (image for the movie), Movie.mp4(video)}. I need my function to open up "Movies" and run through the MovieName file and post each of the contents inside those files. So kinda like a streaming service, I do NOT want to download the url file permanently on the localfile. So kinda think of netflix where they have the image of the movie, with a little description, reviews, etc and it'll stream. You can never download the movie permanently.

"What have I tried?":

I've tried using the firebase link here to guide me but it seems like I'm not understanding it. I've also tried the "list all" list all link but I don't believe it shows the data of each file. Nor was it working for me. Finally I've tried using the URLSession.streamtask() but I've never used that before and so I'll try to successfully use it now by researching more.

"Some code":

func getAlbums() {
    storageref.downloadURL { (url, error) in
        if let error = error {
            print(error.localizedDescription)
        }
        else {
            //get download url
        }
}

According to the firebase link attached this is what I need to do but I don't know how to get the download URL after the else statement.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
mathew
  • 29
  • 5
  • The `url` variable contains the download URL in that else block. To download its contents: http://swiftdeveloperblog.com/code-examples/download-file-from-a-remote-url-in-swift/, https://stackoverflow.com/questions/28219848/how-to-download-file-in-swift and many more from this: https://www.google.com/search?q=swift+download+url – Frank van Puffelen Mar 29 '20 at 14:54
  • @FrankvanPuffelen hi! thank you for your response! I just want to make sure, this isn't going to download the file to the computer right? I would like for it to kinda act like Netflix because I don't want the users to have the files forever. I'm trying to recreate a streaming service. From the looks of it, it looks like ` let documentsUrl:URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL!` this here is sending the file to a destination in the users directory, am i reading it wrong? – mathew Mar 29 '20 at 15:32
  • You'll need to download the data to the local computer, otherwise you can't show it to the user. Whether you create a local file is up to you. – Frank van Puffelen Mar 29 '20 at 15:56
  • @FrankvanPuffelen so I think the answer I was looking for isn't possible and now I pretty much have to be on hold :/ [https://stackoverflow.com/questions/42956250/get-download-url-from-file-uploaded-with-cloud-functions-for-firebase] this and this [https://github.com/googleapis/nodejs-storage/issues/697] state that its not possible to have a permanent link to your URL in your storage that'll load the contents. Or you have to add the functionality yourself. Which idk how to do, but I am up to the challenge as I'll be doing a lot of research. – mathew Mar 30 '20 at 15:24
  • Those answers use the Node.js SDK, while you were using Swift in your question. In Swift (and other client-side SDKs), you can generate download URLs, which don't expire (but can be revoked by you). But at this point it is still unclear to me how to answer your question, so I'm not sure how much more I can help. – Frank van Puffelen Mar 30 '20 at 15:55
  • @FrankvanPuffelen ah shoot, okay so maybe i read it wrong. Maybe im not understanding you? If i create a local file, will the user always have the contents? like i want my app to be on Mac OS and iphone.I read that if I do downloadURL it'll take up space in the memory of the device. So if that's the case, (my app is really about streaming audio) if I use downloadURL the user will be able to have the audio forever. I don't want that because then people would be able to share the audio with their friends and i would want only people who have an account to access the audio. – mathew Mar 30 '20 at 16:00
  • Having a download URL has no impact on whether it is stored, which is why I linked you to some posts that show options of how to handle the data from that URL in your Swift code. But any data that gets onto the user's phone, can also be used on that phone in a way that you may not want. The typical way around that would be to implement some DRM scheme, but that's even more beyond the scope of what we started with here. – Frank van Puffelen Mar 30 '20 at 23:29
  • @FrankvanPuffelen okay i see, ive tried using download URL but i cant seem to get it to work. I keep getting "Object *****/**** does not exist. im doing a search through 2 folders because everything is filtered through song name and then the items are through the song name. Such as the .mp3 and the .jpg. I tried the list all and updating the search queue but it isnt updating with the new items to get the files. – mathew Mar 31 '20 at 17:15

0 Answers0