         data.append("object_id", objectId)
         data.append("attached_file", file)
 
-        xhr = new XMLHttpRequest()
         xhr.upload.addEventListener("progress", uploadProgress, false)
         xhr.addEventListener("load", uploadComplete, false)
         xhr.addEventListener("error", uploadFailed, false)

            defered.reject(response)
            return defered.promise

        uploadProgress = (evt) =>
            $rootScope.$apply =>
                file.status = "in-progress"

                    data = {}

                model =  $model.make_model(urlName, data)
                if xhr.status >= 200 and xhr.status < 400
                    defered.resolve(model)
                else
                    response = {
                        status: xhr.status,
                        data: {_error_message: JSON.parse(xhr.response)['attached_file']?[0]}
                    }
                    defered.reject(response)

        uploadFailed = (evt) =>
            $rootScope.$apply ->
