Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions evaporate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,7 @@
SignedS3AWSRequest.prototype.send.call(self);
});
}
return Promise.resolve();
};
PutPart.prototype.success = function () {
clearInterval(this.stalledInterval);
Expand Down Expand Up @@ -1467,14 +1468,31 @@
return [CANCELED, ABORTED, PAUSED, PAUSING].indexOf(this.fileUpload.status) > -1;
};
PutPart.prototype.delaySend = function () {
var that = this;
var backOffWait = this.backOffWait();
this.attempts += 1;
setTimeout(this.send.bind(this), backOffWait);
setTimeout(function() {
that.send().catch(
function(e) {
l.w(e);
});
}, backOffWait);
};
PutPart.prototype.errorHandler = function (reason) {
clearInterval(this.stalledInterval);
if (reason.match(/status:404/)) {
var errMsg = '404 error on part PUT. The part and the file will abort. ' + reason;
var hasError = false;
var errMsg = "Unexpected error occured";
if (reason instanceof DOMException) {
this.fileUpload.stopMonitor();
errMsg = "Error reading file. " + reason;
hasError = true;
}
else if (reason.match(/status:404/)) {
errMsg = '404 error on part PUT. The part and the file will abort. ' + reason;
hasError = true;
}

if (hasError) {
l.w(errMsg);
this.fileUpload.error(errMsg);
this.part.status = ABORTED;
Expand Down Expand Up @@ -1555,13 +1573,19 @@
// 2nd parameter changed. For example Gecko went from slice(start,length) -> mozSlice(start, end) -> slice(start, end).
// As of 12/12/12, it seems that the unified 'slice' is the best bet, hence it being first in the list. See
// https://developer.mozilla.org/en-US/docs/DOM/Blob for more info.
var that = this;
var file = this.fileUpload.file,
slicerFn = (file.slice ? 'slice' : (file.mozSlice ? 'mozSlice' : 'webkitSlice')),
blob = file[slicerFn](this.start, this.end);
if (this.con.computeContentMd5) {
return new Promise(function (resolve) {
return new Promise(function (resolve, reject) {
var reader = new FileReader();
reader.onloadend = function () {
if (this.error) {
that.errorHandler(this.error);
reject(this.error.message);
return;
}
var buffer = this.result && typeof this.result.buffer !== 'undefined',
result = buffer ? new Uint8Array(this.result.buffer) : this.result;
resolve(result);
Expand Down
38 changes: 38 additions & 0 deletions test/common-case.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import test from 'ava'

let server

if (!global.DOMException) {
global.DOMException = function() {
this.error = undefined
}
}
function testCommon(t, addConfig, initConfig) {
let evapConfig = Object.assign({}, {awsSignatureVersion: '2'}, initConfig)
return testBase(t, addConfig, evapConfig)
Expand Down Expand Up @@ -405,3 +410,36 @@ test('should fail with the correctly ordered requests when PUT part 404s and DEL
expect(requestOrder(t)).to.match(/initiate,PUT:partNumber=1,cancel,cancel/)
})
})

// Failure on FileReader read error is propagated
test.serial('should propagate error when FileReader api fails', (t) => {
var arrayBuffer = global['FileReader'].prototype.readAsArrayBuffer;

global.FileReader.prototype.readAsArrayBuffer = function(blob)
{
this.error = new DOMException();
this.onloadend();
};

const config = {
name: randomAwsKey(),
file: new File({
path: '/tmp/file',
size: 8,
name: randomAwsKey()
}),
computeContentMd5: true,
cryptoMd5Method: function () { return 'MD5Value'; },
}

return testCommon(t, config, config)
.then(
function (result) {
global['FileReader'].prototype.readAsArrayBuffer = arrayBuffer
t.fail('Expected upload to fail but it did not.')
},
function (reason) {
global['FileReader'].prototype.readAsArrayBuffer = arrayBuffer
expect(reason).to.match(/aborted/i)
})
})