diff --git a/addon/file.js b/addon/file.js index 03378b53..0748756a 100644 --- a/addon/file.js +++ b/addon/file.js @@ -176,7 +176,7 @@ export default Ember.Object.extend({ } }); - let request = new HTTPRequest(); + let request = new HTTPRequest({ label: `${options.method} ${get(this, 'name') } to ${options.url}` }); request.open(options.method, options.url); Object.keys(options.headers).forEach(function (key) { @@ -214,29 +214,29 @@ export default Ember.Object.extend({ }, (error) => { set(this, 'state', 'failed'); return RSVP.reject(error); - }).finally(function () { + }, `ember-file-upload: Update "${get(this, 'name')}"'s upload state`).finally(function () { // Decrement for Ember.Test inflightRequests--; }); }, readAsArrayBuffer() { - let reader = new FileReader(); + let reader = new FileReader({ label: `Read ${get(this, 'name')} as an ArrayBuffer` }); return reader.readAsArrayBuffer(this.blob); }, readAsDataURL() { - let reader = new FileReader(); + let reader = new FileReader({ label: `Read ${get(this, 'name')} as a Data URI` }); return reader.readAsDataURL(this.blob); }, readAsBinaryString() { - let reader = new FileReader(); + let reader = new FileReader({ label: `Read ${get(this, 'name')} as a binary string` }); return reader.readAsBinaryString(this.blob); }, readAsText() { - let reader = new FileReader(); + let reader = new FileReader({ label: `Read ${get(this, 'name')} as text` }); return reader.readAsText(this.blob); } diff --git a/addon/system/file-reader.js b/addon/system/file-reader.js index 30787ccd..be28902e 100644 --- a/addon/system/file-reader.js +++ b/addon/system/file-reader.js @@ -2,16 +2,19 @@ import Ember from 'ember'; const { RSVP } = Ember; -export default function () { - let { resolve, reject, promise } = RSVP.defer(); +export default function (options = {}) { + let { resolve, reject, promise } = RSVP.defer(`ember-file-upload: ${options.label}`); let reader = new FileReader(); reader.onload = resolve; reader.onerror = reject; - let aborted = RSVP.defer(); + let aborted; let cancel = function () { - reader.abort(); + if (aborted == null) { + aborted = RSVP.defer(`ember-file-upload: Abort ${options.label}`); + reader.abort(); + } return aborted.promise; }; reader.onabort = function () { @@ -25,7 +28,7 @@ export default function () { return reader.result; }, function () { return RSVP.reject(reader.error); - }); + }, `ember-file-upload: Unpack ${options.label}`); p.cancel = cancel; return p; }; diff --git a/addon/system/http-request.js b/addon/system/http-request.js index d06a5460..ea3bb715 100644 --- a/addon/system/http-request.js +++ b/addon/system/http-request.js @@ -47,13 +47,16 @@ function parseResponse(request) { }; } -export default function () { - let { resolve, reject, promise } = RSVP.defer(); +export default function (options = {}) { + let { resolve, reject, promise } = RSVP.defer(`ember-file-upload: ${options.label}`); let request = new XMLHttpRequest(); - let aborted = RSVP.defer(); + let aborted; promise.cancel = () => { - request.abort(); + if (aborted == null) { + aborted = RSVP.defer(`ember-file-upload: Abort ${options.label}`); + request.abort(); + } return aborted.promise; }; request.onabort = bind(this, function () {