BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

What would be the Best way to download a file? REST API or directly from a URL?

Forums > SwiftUI

I have a an application (Microsoft Blazor App) that my customers can upload files to and attach to items. It can litteraly be any type of file.

My iOS application (SwiftUI) that I am creating gives the user the ability to download those files and view them while out in the field.

In the past I just called my REST API that would return that file as a base64 string and then I turned it into a file and saved it with the data in Core Data (or now Swift Data). This works fine.

I was thinking, instead of sending a request for the file and then getting back the base64 string, I could just send the URL to the file directly and just do a URL Session data request, and then save the data within the database.

Would you see any difference or performance over one or the other. My customers are using iPads in the field with a cellular connection, so sometimes speed isn't the best.

Any suggestions?

   

It's just my personal opinion but, given that there is an API, I would use the API.

Performance is importnt but the robustness of your app is not to be ignored. By using the API you guarantee the availability of the file and have the flexibility to change the back end whenever you need to. If you download a file from a URL, you run the risk of the file being moved somewhere else and your app crashing until you can rebuild it with the new URL and get it distributed. Using the API puts a safety net between your app and the back end server.

Steve.

   

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.