title: Swift 3: Transfer Utility, how to retry upload after failure?
body: <p>This is how my completionHandler looks like:</p>
  
  <pre><code>self.completionHandler = { (task, error) -&gt; Void in
          DispatchQueue.main.async(execute: {
              if ((error) != nil){
  
                  //retry upload
              }
  
              else{
  
                  //success
              }
          })
  
      }
  </code></pre>
  
  <p>I don't see any method I can call on <code>task</code> to retry it, I only see <code>continue</code> method, but not sure how to use it.</p>
  
  <p>I start upload for the first time the following way:</p>
  
  <pre><code>transferUtility.uploadData(
          data as Data,
          bucket: "test",
          key: "testTU3/try\(Date()).jpeg",
          contentType: "image/jpeg",
          expression: expression,
          completionHander: completionHandler).continue(successBlock: { (task) -&gt; AnyObject! in
              if let error = task.error {
                  NSLog("Error: %@",error.localizedDescription);
  
              }
              if let exception = task.exception {
                  NSLog("Exception: %@",exception.description);
  
              }
              if let _ = task.result {
  
                  NSLog("Upload Starting!")
                  // Do something with uploadTask.
              }
  
              return nil;
          })
  </code></pre>
  
  <p>How to retry upload in completionHandler after failure?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>here is what I've tried</p>
  
  <pre><code> self.completionHandler = { (task, error) -&gt; Void in
          DispatchQueue.main.async(execute: {
              if ((error) != nil){
                  guard let data = task.request?.httpBody else {return}
                  self.uploadData(data: data as NSData, bucket: task.bucket, key: task.key)
  
              }
  
              else{
              }
          })
      }
  </code></pre>
  
  <p>But the problem is that I can't get the actual data of the request since </p>
  
  <p><code>task.request?.httpBody</code> evaluates to nil.</p>
  
  <p>Is such approach a good idea? I know it might lead to endless running loop</p>