最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

iOS BGProcessingTask File AWS S3 Upload Limits - Stack Overflow

programmeradmin1浏览0评论

I have BGProcessingTask & BGAppRefreshTask working fine. The main purpose of my use of BGProcessingTask is to upload a file to AWS S3 using multipart/form-data. I have found that any file above about 2.5MB times out after running almost four minutes. If I run the same RESTful api using curl or Postman, I can upload a 25MB file in 3 seconds or less.

I have tried to deliberately set .earliestBeginDate to 01:00 or 02:00 local time on the iPhone, but that does not seem to help.

I use the delegate (yes, I am writing in Objective C) - URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend: and find that the iOS system uploads about 140kB every 15 seconds or so.

I am looking for recommendations or insight into how I might enable uploads of 25MB files. I would be happy it I could do just one a day for my use case.

I provide code on how I set up the NSURLSession and NSURLSessionDownloadTask, as it is my guess that if there is something that needs to be modified it is there. I have to believe there is a solution for this since I read in many posts here and in Apple Developer how developers are using this functionality for uploading many, many files.

NSURLSessionConfiguration *sConf            =   [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:bkto.taskIdentifier];
    sConf.URLCache                          =   [NSURLCache sharedURLCache];
    sConf.waitsForConnectivity              =   YES;
    sConf.allowsCellularAccess              =   NO;
    sConfworkServiceType                =   NSURLNetworkServiceTypeVideot;
    sConf.multipathServiceType              =   NSURLSessionMultipathServiceTypeNone;
    sConf.discretionary                     =   YES;
    sConf.timeoutIntervalForResource        =   kONEHOURINTERVAL;
    sConf.timeoutIntervalForRequest         =   kONEMINUTEINTERVAL;
    sConf.allowsExpensiveNetworkAccess      =   NO ;
    sConf.allowsConstrainedNetworkAccess    =   NO;
    sConf.sessionSendsLaunchEvents          =   YES;
    myURLSession = [NSURLSession sessionWithConfiguration:sConf delegate:self delegateQueue:nil];

and later

NSMutableURLRequest *request        =   [NSMutableURLRequest requestWithURL:[NSURL URLWithString:pth]];
    request.HTTPMethod              =   kHTTPPOST;
    request.HTTPBody                =   [NSData my body data];
    request.timeoutInterval         =   60;                                                                             
    [request setValue:@"*/*" forHTTPHeaderField:@"Accept"];
    [request setValue:@"en-us,en" forHTTPHeaderField:@"Accept-Language"];
    [request setValue:@"gzip, deflate, br" forHTTPHeaderField:@"Accept-Encoding"];
    [request setValue:@"ISO-8859-1,utf-8" forHTTPHeaderField:@"Accept-Charset"];
    [request setValue:@"600" forHTTPHeaderField:@"Keep-Alive"];                                                                 
    [request setValue:@"keep-alive" forHTTPHeaderField:@"Connection"];
    NSString *contType              =   [NSString stringWithFormat:@"multipart/form-data; boundary=%@",bnd];
    [request setValue:contType forHTTPHeaderField:@"Content-Type"];
    [request addValue:[NSString stringWithFormat:@"%lu",(unsigned long)myData.length] forHTTPHeaderField:@"Content-Length"];

    NSURLSessionDownloadTask *downloadTask          =   [myURLSession downloadTaskWithRequest:request];
    downloadTask.countOfBytesClientExpectsToSend    =   bd.length + 500;
    downloadTask.countOfBytesClientExpectsToReceive =   5000;
    NSLog(@"%s: downloadTask = %@,  time  %@",__FUNCTION__,downloadTask,[NSDate date]);
    [downloadTask resume];

and here are logs showing the infrequent uploads of small data chunks:

-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: task = BackgroundDownloadTask <76A81A80-4703-4686-8742-A0048EB65108>.<2>, time  Fri Mar  7 16:25:21 2025
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: bytesSent = 393,216
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: totalBytesSent = 393,216
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: task = BackgroundDownloadTask <76A81A80-4703-4686-8742-A0048EB65108>.<2>, time  Fri Mar  7 16:25:27 2025
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: bytesSent = 131,072
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: totalBytesSent = 524,288
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: task = BackgroundDownloadTask <76A81A80-4703-4686-8742-A0048EB65108>.<2>, time  Fri Mar  7 16:25:42 2025
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: bytesSent = 131,072
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: totalBytesSent = 655,360
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: task = BackgroundDownloadTask <76A81A80-4703-4686-8742-A0048EB65108>.<2>, time  Fri Mar  7 16:25:56 2025
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: bytesSent = 131,072
-[BKSessionManager URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]: totalBytesSent = 786,432
发布评论

评论列表(0)

  1. 暂无评论