                 request.setValue(value, forHTTPHeaderField: "metadata_\(key)")
             }
         }
-        
         request.timeoutInterval = 60 * 5
         request.setValue("Bearer \(MMCoreConfiguration.serviceAdapter.HATToken)", forHTTPHeaderField: "Authorization")
         
-        let uploadTask = MMCoreConfiguration.serviceAdapter.backgroundSessionManager.uploadTaskWithStreamedRequest(request, progress:&progress) { response, responseObject, error in
+        var progressObject : MMAttachmentProgress = MMAttachmentProgress.init()
+        if let prog = progress {
+            progressObject = prog
+        }
+        
+        let uploadTask = MMCoreConfiguration.serviceAdapter.backgroundSessionManager.uploadTaskWithStreamedRequest(request, progress:&progressObject.uploadProgress) { response, responseObject, error in
             if let e = error {
                 failure?(error: e)
             } else {

    }
    
    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)"

        let request = NSMutableURLRequest(URL: downloadURL)
        request.setValue("Bearer \(MMCoreConfiguration.serviceAdapter.HATToken)", forHTTPHeaderField: "Authorization")
        request.timeoutInterval = 60 * 5
        
        var prog = progress?.downloadProgress
        let downloadTask = MMCoreConfiguration.serviceAdapter.backgroundSessionManager.downloadTaskWithRequest(request, progress: &prog, 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)
