我正在开发一个需要将大文件上传到服务器的项目。我使用 NSURLSession 来设置后台传输服务。一切似乎都很好,但是我相信它会继续发送 32K 的块。我想知道是否有办法增加块大小?
以下是设置上传任务的示例代码:
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:identifier];
sessionConfig.HTTPMaximumConnectionsPerHost = 1;
NSURLSession *upLoadSession = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];
NSMutableURLRequest *request = [self configureURLRequest];
NSURLSessionUploadTask *uploadTask = [upLoadSession uploadTaskWithRequest:request fromFile:[NSURL fileURLWithPath:filePath]];
[uploadTask resume];
这是委托示例代码:
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
DLog(@"didSendBodyData: %lld, totalBytesSent: %lld, totalBytesExpectedToSend: %lld", bytesSent, totalBytesSent, totalBytesExpectedToSend);
}
同样,有没有办法增加使用 NSURLSession 上传的块大小?默认为 32K。