0

I am experiencing some weird behaviour when using an uploadTask for a URLSessionConfiguration.background.

My custom delegate is implementing all of the delegate methods that belong to URLSessionDelegate, URLSessionTaskDelegate, and URLSessionDataDelegate. All of them has a print statement indicating that the method has been called.

I am trying to upload five images to a server, each of them has their own session with an id matching the image id.

The problem is that when uploading using a very slow connection "edge", the upload progress will reset before reaching 100% This happens whenever didFinishCollectingMetrics is called as you can see here: Data

This does not happen all the time when using a slow connection but only some of the time.

Anyone got any ideas as to what is happening here?

Developer
  • 736
  • 7
  • 30

2 Answers2

1

Edge networking is notoriously unreliable, and frequent upload failures are not atypical. The way you solve this is by replacing whole-file-based uploads with some form of chunked uploads so that you can continue the upload where you left off, but that requires server support.

dgatwood
  • 10,129
  • 1
  • 28
  • 49
0

Increase time-out of NSURLSession for request and resource:

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
[configuration setTimeoutIntervalForRequest:120];
[configuration setTimeoutIntervalForResource:240];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];

Use session to upload your image

  • @zain-dev Thank you for the answer. It does not seem to fix the problem. I tried to set the timeouts to `300` but now I get the message "The request timed out." which I did not get before. – Developer Dec 14 '16 at 13:14
  • @frederik di u solve the problem? i have the same problem but with video uploding. Thanks – Denis Bulgarini Aug 16 '17 at 13:36