Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Multiple file Upload in Background Transfer Service

$
0
0

Hi Xamarin iOS experts,

I have an app where a user creates a news item and upload images for that news item. the way I designed it is users can keep submitting news items and app would create subfolders with images and a txt file with all metadata in it. I would need a background process that keeps monitoring the transfer folder and first call a REST endpoint to create news item and then upload images for that item. this process need to be run all the time even when the app is terminated or is in background. so I would like to have something like this:

while(true) { List transfer_subforlders = FileService.GetTransferSubfoilders(); foreach(path in transfer_subforlders) { //read the txt file and create a news item //get news item id from DB

     // Loop through images in current folder and upload them one by one

}

}

Now my issue is that all samples i found for using NSURLSession are for a single upload . How would I approach for a case like this where I need call a REST service first to create a news item and then use its id to upload associated images one by one. How the NSURLSessionDelegate methods would be in this case? Can i start new upload tasks when all tasks are done?

So imagine I create 3 tasks for 3 image upload by using below:

NSUrl downloadURL1 = NSUrl.FromString (DownloadURLString1); NSUrlRequest request1 = NSUrlRequest.FromUrl (downloadURL1); downloadTask1 = session.CreateDownloadTask (request1);

NSUrl downloadURL2 = NSUrl.FromString (DownloadURLString2); NSUrlRequest request2 = NSUrlRequest.FromUrl (downloadURL2); downloadTask2 = session.CreateDownloadTask (request2);

NSUrl downloadURL3 = NSUrl.FromString (DownloadURLString3); NSUrlRequest request3 = NSUrlRequest.FromUrl (downloadURL3); downloadTask3 = session.CreateDownloadTask (request3);

then my understanding is that when ALL three are done it would call below and I can create another 3 tasks here using session.CreateDownloadTask . Is that right?

public override void DidFinishEventsForBackgroundSession (NSUrlSession session) { //Can I here check is transfer folder has more images or there are more transfer folders for other items and create more tasks?

}

Really appreciate your help, Thanks,


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>