             }
         }
         
+        request.timeoutInterval = 60 * 5
         request.setValue("Bearer \(MMCoreConfiguration.serviceAdapter.HATToken)", forHTTPHeaderField: "Authorization")
-        let uploadTask = MMCoreConfiguration.serviceAdapter.backgroundSessionManager.uploadTaskWithStreamedRequest(request, progress: nil) { response, responseObject, error in
+        
+        let uploadTask = MMCoreConfiguration.serviceAdapter.backgroundSessionManager.uploadTaskWithStreamedRequest(request, progress:&progress) { response, responseObject, error in
             if let e = error {
                 failure?(error: e)
             } else {

        }
        let request = NSMutableURLRequest(URL: downloadURL)
        request.setValue("Bearer \(MMCoreConfiguration.serviceAdapter.HATToken)", forHTTPHeaderField: "Authorization")
        
        let downloadTask = MMCoreConfiguration.serviceAdapter.backgroundSessionManager.downloadTaskWithRequest(request, progress: nil, destination: { targetPath, response in
            let documentsDirectoryURL = try! NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
            let destination  = documentsDirectoryURL.URLByAppendingPathComponent("\(attachmentID)_\(response.suggestedFilename!)")
            //            let _ = try? NSFileManager.defaultManager().removeItemAtURL(destination)
            return destination
            
        }) { response, filePath, error in
            if let e = error {
                failure?(error: e)
            } else {
//                guard let httpResponse = response as? NSHTTPURLResponse else {
//                    fatalError("response should be of type NSHTTPURLResponse")
//                }
//                let headers = httpResponse.allHeaderFields["Content-Type"] as! [String: AnyObject]
//                var contentType = "application/octet-stream"
//                if let contentTypeHeader = headers["Content-Type"] as? String {
//                    contentType = contentTypeHeader
//                }
                    success?(filePath!)
                }
        }

    }
    
    static public func download(attachmentID: String, userID userIdentifier: String?, success: ((NSURL) -> ())?, failure: ((error: NSError) -> Void)?) {
        var progress : NSProgress? = nil
        download(attachmentID, userID: userIdentifier, progress: &progress, success: success, failure: failure)
    }
    
    static public func download(attachmentID: String, userID userIdentifier: String?, inout progress : NSProgress?, success: ((NSURL) -> ())?, failure: ((error: NSError) -> Void)?) {
        var userIDQueryParam = ""
        if let userID = userIdentifier {
            userIDQueryParam = "?user_id=\(userID)"
