1 Reply
      Latest reply on Nov 21, 2019 5:12 AM by gupta.h
      Rakshit_SoftNWeb Level 1 Level 1 (0 points)

        DownloadTask downloads authenticated videos from VIMEO using video urls with request on Background Session. It works well for small size videos but task fails for large HQ videos and I cannot  resume it or help me to fetch partially downloaded data.


        As per logs involved in didFinishCollecting metrics delegate (shown at last): Video url does 1 direct and after that task finishes with below error


        Please guide me for:

        1. How to collect partially downloaded data by download task  so i can resume task when task failed and data is not available with error userinfo ?

         

        Error Log :

        1. localized error: Optional(\"The operation couldn’t be completed. Protocol error\")
        2. error debug description: Optional(Error Domain=NSPOSIXErrorDomain Code=100 \"Protocol error\" UserInfo={_kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=100, NSErrorPeerAddressKey=<100201bb 97650a6d 00000000 00000000>})
        3. error unsafelyUnwrapped :Error Domain=NSPOSIXErrorDomain Code=100 \"Protocol error\" UserInfo={_kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=100, NSErrorPeerAddressKey=<100201bb 97650a6d 00000000 00000000>}"

         

        CODE:

         

        var downloadTask: URLSessionDownloadTask?

        var SessionRequest : URLRequest?

         

        let backgroundSessionConfiguration = URLSessionConfiguration.background(withIdentifier: "\(Bundle.main.bundleIdentifier!).background")

         

        let url = URL(string: urlString)!

        SessionRequest = URLRequest(url: url)

        SessionRequest?.httpMethod = "GET"

        downloadTask = backgroundSession.downloadTask(with: SessionRequest!)

        downloadTask?.resume()

         

        func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {

             if error != nil {

                                  debugPrint("Task completed: \(String(describing: task)),localized error: \(String(describing:                  error?.localizedDescription)) error debug desc: \(String(describing: error.debugDescription)) error unsafelyUnwrapped :\(error.unsafelyUnwrapped)")

         

                                 let err = error! as NSError

                                 let data = (err.userInfo)[NSURLSessionDownloadTaskResumeData]

                                                                //Above data is always nil so cannot resume

                             }

        }

         

        CODE Ends



        didFinishCollecting metrics delegate Logs:

         

        transMetrics:(Request) <NSURLRequest: 0x60000000f0a0> { URL: "video URL"}

        (Response) (null)

        (Fetch Start) 2017-06-09 08:25:58 +0000

        (Domain Lookup Start) (null)

        (Domain Lookup End) (null)

        (Connect Start) (null)

        (Secure Connection Start) (null)

        (Secure Connection End) (null)

        (Connect End) (null)

        (Request Start) (null)

        (Request End) (null)

        (Response Start) (null)

        (Response End) (null)

        (Protocol Name) (null)

        (Proxy Connection) NO

        (Reused Connection) YES

        (Fetch Type) Unknown

         

         

         

         

         

         

        networkProtocolName:Optional("\"http/1.1\"")

         

        resourceFetchType:1

         

        transMetrics:(Request) <NSURLRequest: 0x600000005f50> { URL: redirected url }

        (Response) <NSHTTPURLResponse: 0x600000625f20> { URL: redirected url } { status code: 302, headers {

            "Accept-Ranges" = bytes;

            "Access-Control-Allow-Origin" = "*";

            Age = 0;

            "Cache-Control" = "private, max-age=14400";

            Connection = "keep-alive";

            "Content-Length" = 0;

            "Content-Security-Policy" = "default-src 'self'; script-src 'self' https://f.vimeocdn.com; style-src 'self' https://f.vimeocdn.com; img-src 'self' https://i.vimeocdn.com https://f.vimeocdn.com";

            "Content-Type" = "text/html; charset=UTF-8";

            Date = "Fri, 09 Jun 2017 08:25:58 GMT";

            Expires = "Fri, 09 Jun 2017 12:25:58 GMT";

            "Fastly-Debug-Digest" = 40c074ff9698ac2af43069e1f6f5714080fb3224371a0af2b06b11357d8bfe3d;

            Location = "video location";

            P3p = "CP=\"This is not a P3P policy! See https://vimeo.com/privacy\"";

            Server = nginx;

            "Strict-Transport-Security" = "max-age=15552000; includeSubDomains; preload";

            Vary = "Accept-Encoding";

            Via = "1.1 varnish, 1.1 varnish, 1.1 varnish";

            "X-Cache" = "MISS, MISS";

            "X-Cache-Hits" = "0, 0";

            "X-Content-Type-Options" = nosniff;

            "X-Served-By" = "cache-iad2149-IAD, cache-hhn1525-HHN";

            "X-Timer" = "S1496996758.243466,VS0,VE115";

            "X-VServer" = dfvimeoplayproxy3;

            "X-Varnish-Cache" = 0;

            "X-Xss-Protection" = "1; mode=block";

        } }

        (Fetch Start) 2017-06-09 08:26:00 +0000

        (Domain Lookup Start) 2017-06-09 08:25:58 +0000

        (Domain Lookup End) 2017-06-09 08:25:59 +0000

        (Connect Start) 2017-06-09 08:25:59 +0000

        (Secure Connection Start) 2017-06-09 08:25:59 +0000

        (Secure Connection End) 2017-06-09 08:26:00 +0000

        (Connect End) 2017-06-09 08:26:00 +0000

        (Request Start) 2017-06-09 08:26:00 +0000

        (Request End) 2017-06-09 08:26:00 +0000

        (Response Start) 2017-06-09 08:26:00 +0000

        (Response End) 2017-06-09 08:26:00 +0000

        (Protocol Name) http/1.1

        (Proxy Connection) NO

        (Reused Connection) NO

        (Fetch Type) Network Load

         

         

         

         

         

         

        networkProtocolName:Optional("\"h2\"")

         

        resourceFetchType:1

         

        transMetrics:(Request) <NSURLRequest: 0x60000000f270> { URL: "video URL" }

        (Response) <NSHTTPURLResponse: 0x600000626500> { URL: "video URL" } { status code: 200, headers {

            "Accept-Ranges" = bytes;

            "Access-Control-Allow-Origin" = "*";

            "Content-Length" = 26480993;

            "Content-Type" = "video/mp4";

            Date = "Fri, 09 Jun 2017 08:25:59 GMT";

            Etag = "\"13ff593bc8efb781de43cc1b8755fbf9\"";

            Expires = "Wed, 07 Jun 2017 12:57:51 GMT";

            "Last-Modified" = "Fri, 26 May 2017 12:28:32 GMT";

            Server = UploadServer;

            Via = "1.1 varnish, 1.1 varnish, 1.1 varnish";

            "access-control-allow-headers" = "Content-Type, Accept-Encoding, Range";

            "fastly-debug-digest" = 376baf493d3a606878cbf3be0424271bb79eb2eba4fb6b378b3917c486311b37;

            "timing-allow-origin" = "*";

            "x-cache" = "MISS, HIT, HIT";

            "x-cache-hits" = "0, 0, 0";

            "x-served-by" = "cache-iad2151-IAD, cache-lax8623-LAX, cache-sin18029-SIN";

            "x-timer" = "S1496996759.315739,VS0,VE0";

        } }

        (Fetch Start) 2017-06-09 08:26:00 +0000

        (Domain Lookup Start) 2017-06-09 08:26:00 +0000

        (Domain Lookup End) 2017-06-09 08:26:00 +0000

        (Connect Start) 2017-06-09 08:26:00 +0000

        (Secure Connection Start) 2017-06-09 08:26:00 +0000

        (Secure Connection End) 2017-06-09 08:26:01 +0000

        (Connect End) 2017-06-09 08:26:01 +0000

        (Request Start) 2017-06-09 08:26:01 +0000

        (Request End) 2017-06-09 08:26:01 +0000

        (Response Start) 2017-06-09 08:26:01 +0000

        (Response End) 2017-06-09 08:27:01 +0000

        (Protocol Name) h2

        (Proxy Connection) NO

        (Reused Connection) NO

        (Fetch Type) Network Load