NSURLSession uploads huge files

I am trying to upload a large 2 GB file in the background using NSURLSessionUploadTask . The service uses a multi-page format, so to download it in the background, I create a temporary file with the request body, then I use uploadTask to schedule the download and when the files finish downloading, I delete the temporary file.

NSURLSessionUploadTask *uploadTask = [[self backgroundNSURLSession] uploadTaskWithRequest:uploadRequest fromFile:filePath]; [uploadTask resume];

With files less than 1.4 GB, the download worked fine, but when I try to download 2 GB video files, the download failed. The server returns an error message that I did not attach the file.

I will reorganize the download component from ASIHTTP to NSURLSession, if I download from ASIHTTP, it works even for large files.

This is how I create my NSURLSession:

  if ([NSURLSessionConfiguration respondsToSelector:@selector(backgroundSessionConfigurationWithIdentifier:)]) { self.configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:appID]; } else { self.configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:appID]; } self.configuration.HTTPMaximumConnectionsPerHost = 1; self.configuration.discretionary = YES; self.configuration.timeoutIntervalForResource = 60*60; self.configuration.timeoutIntervalForRequest = 60*60; backgroundSession = [NSURLSession sessionWithConfiguration:self.configuration delegate:self delegateQueue:nil]; 

Thus, the problem is only in large files, loading is performed for small files. Has anyone else encountered the same problem?

+5
source share
1 answer

As described by the apple developer for the discretionary property, if the file is so large, the system can expect a good moment, for example, a WIFI connection.

Switch the discretionary property to NO and try again. good luck!

self.configuration.discretionary = NO;

0
source

Source: https://habr.com/ru/post/1205886/


All Articles