             }
             
             // Do the work:
-            if (skipResumeCheck) {
-                let data = upload.getData()
-                let chunks = self.dataIntoChunks(data: data, chunkSize: TUSClient.shared.chunkSize)
-                startUpload(chunks: chunks)
-            } else {
-                self.prepareUpload(forUpload: upload) { (chunks, skipUploadMarkSuccess) in
-                    if (skipUploadMarkSuccess) {
-                        self.handleUploadSuccess(upload: upload, completion: uploadFinishedCallback)
-                    } else {
-                        startUpload(chunks: chunks)
+            do {
+                let data = try upload.getData()
+                if (skipResumeCheck) {
+                    let chunks = self.dataIntoChunks(data: data, chunkSize: TUSClient.shared.chunkSize)
+                    startUpload(chunks: chunks)
+                } else {
+                    self.prepareUpload(forUpload: upload, uploadData: data) { (chunks, skipUploadMarkSuccess) in
+                        if (skipUploadMarkSuccess) {
+                            self.handleUploadSuccess(upload: upload, completion: uploadFinishedCallback)
+                        } else {
+                            startUpload(chunks: chunks)
+                        }
                     }
                 }
+            } catch {
+                self.markAsFailed(upload: upload, completion: uploadFinishedCallback, error: error)
             }
         }
     }

                case 400 ..< 500:
                    // reuqest error
                    TUSClient.shared.logger.log(forLevel: .Error, withMessage: String(format: "Received request failure status code %u", httpResponse.statusCode))
                    markAsFailed(upload: upload, error: nil)
                case 500 ..< 600:
                    // server
                    TUSClient.shared.logger.log(forLevel: .Error, withMessage: String(format: "Received server failure status code %u", httpResponse.statusCode))
                    markAsFailed(upload: upload, error: nil)
                default: break
                }
            } else {
                TUSClient.shared.logger.log(forLevel: .Error, withMessage: "Server response couldn't be parsed!")
                markAsFailed(upload: upload, error: nil)
            }
        })
        pendingUploadTasks[upload.id] = task

        // Get from which point we should start the uploading (important if the file
        // has already been partially uploaded)
        checkForResumableOffset(uploadUrl: upload.uploadLocationURL!) { (uploadOffset) in
            // Create chunks to upload, eventually starting from the uploadOffset we retrieved
            let chunks = self.dataIntoChunks(data: uploadData,
                                             chunkSize: TUSClient.shared.chunkSize,
