         let request = NSMutableURLRequest(URL: downloadURL)
         request.setValue("Bearer \(MMCoreConfiguration.serviceAdapter.HATToken)", forHTTPHeaderField: "Authorization")
         request.timeoutInterval = 60 * 5
-        let downloadTask = MMCoreConfiguration.serviceAdapter.backgroundSessionManager.downloadTaskWithRequest(request, progress: &progress, destination: { targetPath, response in
+        
+        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)

import Foundation
import AFNetworking

@objc public class MMAttachmentService: NSObject {
    
    static public func upload(attachments: [MMAttachment], metaData:[String: String]?, success: (() -> ())?, failure: ((error: NSError) -> Void)?) {
        var progress : NSProgress? = nil
        upload(attachments, metaData: metaData, progress: &progress, success: success, failure: failure)
    }
    
    static public func upload(attachments: [MMAttachment], metaData:[String: String]?, inout progress : NSProgress?, success: (() -> ())?, failure: ((error: NSError) -> Void)?) {
        guard let uploadURL = NSURL(string: "com.magnet.server/file/save/multiple", relativeToURL: MMCoreConfiguration.serviceAdapter.endPoint.URL)?.absoluteString else {
            fatalError("uploadURL should not be nil")
        }

                request.setValue(value, forHTTPHeaderField: "metadata_\(key)")
            }
        }
        request.timeoutInterval = 60 * 5
        request.setValue("Bearer \(MMCoreConfiguration.serviceAdapter.HATToken)", forHTTPHeaderField: "Authorization")
        
        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 {
