URLSession - Download remote directory - ios

I am currently using code based on this turtorial http://sweettutos.com/2015/11/06/networking-in-swift-how-to-download-a-file-with-nsurlsession/ to download a remote file using URLSession.downloadTask. This was suprisingly simple. However I would now like to download the entire contents of a remote directory.
Can I use URLSessionDownloadTask or is this only for single files? If not then how can I obtain a list of the files contained in the remote directory so that I can use downloadTask on each of them individually?

First of all you are thinking it in wrong way.
From the remote server, only a file that can be downloaded(not the folder) and save inside the app. The file extension that you have to download should be configure from a server side. Then the client side which you can use Sweettutos tutorial.
First thing you have to do was :
Talk with the server side developer that he had to zip the remote directory in (.zip or .rar) that you can download it only.
Then, at your code download the url which the server-side given to you and save it in document directory, extract and read the file which you want to.
At the URLSession Documentation :
Download tasks retrieve data in the form of a file, and support
background downloads and uploads while the app is not running.
So, there is no way you can download remote directory (unknown file extension) until you make that remote file available to some file extensions from the server-side.

Related

Serve audio file from GCS with Rails

I have audio files located on a private GCS bucket. I want to serve these audio files for users to listen to.
I cant use Active Storage for this as these files are created/deleted outside of my Rails application.
I could download files using google-cloud-storage gem. It would cover authentication, file download. But if I understand correctly I can only serve files from the public directory? So do I need to download those to Rails.public_path?
Furthermore, I really don't want to manage these files after downloading them - caching, deleting them after some time, etc.
What would be the best way to achieve this?
The best option in my opinion would be to use the google-cloud-storage gem,
since both Google::Cloud::Storage::Bucket and Google::Cloud::Storage::File have the #signed_url method. This way you can find the relevant file(s) that you need and create a temporary url, send the url to the client, which will be in charge of downloading the file directly.
If you don't want the client do download the file directly from Google Cloud you can just download the file from GC yourself, and use #send_data or #send_file in the controller.

Uploading an image from iOS to Azure File Share

I have found documentation for uploading an image from iOS to a blob container in Azure - https://learn.microsoft.com/en-us/azure/storage/blobs/storage-ios-how-to-use-blob-storage
using the https://github.com/Azure/azure-storage-ios library
But I wish to upload directly to a file share. Is there a way to do this?
It needs to be implemented using SAS authentication.
Unfortunately I am not familiar with iOS programming thus I will not be able to provide you any code. However you can use the steps below to write code.
Assuming you have a SAS URL for the file share in which you wish to upload the file, you can simply use Azure Storage REST API to upload the file in a file share. You should be able to use built-in HTTP functionality in the programming language of your choice to do that.
Let's assume that you have a SAS URL for the file share in the following format: https://<account-name>.file.core.windows.net/<share-name>?<sas-token>.
First thing you would need to do is insert the file name that you wish to upload in this SAS URL so that you get a SAS URL for the file. Your SAS URL would look something like: https://<account-name>.file.core.windows.net/<share-name>/<file-name>?<sas-token>.
Next you would need to create an empty file. You will use Create File REST API operation. Do not worry about the Authorization request header there as it is already included in the SAS. Only request header you would need to include is x-ms-content-length value of which should be the size of the file you want to upload. This will create an empty file having size as that of the file you want to upload.
Once this operation completes, next you would need to upload the data in the empty file you just created. You will use Put Range operation. The request headers you need to include are x-ms-range (value of which should be bytes=0-file-length - 1) and Content-Length (value of which should be the length of your file). The request body will contain the file contents.
Using these steps you should be able to upload a file in a file share.

What are usage examples for NSFileProviderExtension in Swift?

It seems like the NSFileProviderExtension inherits from NSObject.
The apple documentation here does not have any usage examples.
Thanks in advance.
From the docs:
https://developer.apple.com/documentation/fileprovider
If your app is primarily focused on storing and managing user documents, you can implement a File Provider extension to give users access to their content while they're using other apps.
Your file provider provides access to files stored on your server.
The File Provider extension:
Creates placeholders for remote files that you download only as needed.
Intercepts coordinated reads from the host app, so that the file can be downloaded or updated from the remote server before the read occurs.
Triggers a notification after coordinated writes from the host app, so that the extension can upload the changes to the remote server as needed.
Enumerates the stored documents and folders.
Executes actions—such as importing, moving, renaming, or deleting items—on the stored documents and folders.

How can i set "FILES_ROOT" to a folder on server?

I want to use RoxyFileMan to manage uploaded images and files. But I should save them on the server. As you know, RoxyFileMan Upload uploads files and images in a folder named Uploads in a fileman directory. We can change FILES_ROOT to another local path to change the directory files get uploaded to.
But, I want to upload files on the server and then read them from the server after they've been uploaded so that they can be edited in ckeditor.
Can anyone please provide advice/guidance on how to achive this outcome?
It's not very clear how your question is meant, but if I understand you correctly, you are using RoxyFileMan on a local server and want to upload files to a remote online server, right?
Roxy uploads files to a directory on the server it is run from. Which means if run from localhost, it will use directory on your localhost. If run from a server, it will use a directory on server.
As far as my knowledge goes, you cannot upload from a localhost to an online server directly.
You could maybe achieve that using some custom script to open an FTP connection, but then you would have to also remake all the code to also load images from there... which would be rather silly.

Download all available (and new) files

I'm using NSURLSessionDownloadTask to download some .mov files from a web and storing them in my app.
Now what I'd like to achieve is to
download ALL files of certain type (in this case .mov) available on the page, without having to specify every file URL
download files ONLY if they are not already stored in my app.
Is there any way to achieve this?
You would have to scrape that html page to get all the urls (.mov) you are looking for. Either you can use NSXMLParser if you want to write your own or you can google some library.
When you download a file, persist some metadata (eg. name or some unique identifier) either in SQLite or CoreData, so that you can check if the file has already been downloaded.

Resources