5

I am trying to upload a large file 2GB in the background using NSURLSessionUploadTask. The service uses multipart format, so in order to upload it in the background i am creating a temporary file with the Body of the request, then i am using a uploadTask to schedule the upload and when the files finishes uploading i am deleting the temporary file.

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

With files smaller then 1.4 GB the upload worked ok, but when I try to upload video files of 2 GB, the upload fails. Server is returning error message that i did not attached the file.

I am refactoring the upload component from ASIHTTP to NSURLSession if i do the upload with 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];

So the problem is only for large files, for small files the upload is performed. Has anyone else encountered the same problem?

Mihai Georgescu
  • 374
  • 4
  • 16

1 Answers1

0

According with apple developer description for property discretionary if the file is so large, the system might be waiting for a good moment like a WIFI connection.

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

self.configuration.discretionary = NO;
Lukas Würzburger
  • 6,207
  • 7
  • 35
  • 68
vibroto
  • 31
  • 4