Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
fix(azure): multi-part upload to S3 fails on Edge >= 15
Browse files Browse the repository at this point in the history
fixes #1852
  • Loading branch information
galvinhsiu authored and rnicholus committed Jun 27, 2017
1 parent fc5923f commit a060e50
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions client/js/s3/s3.xhr.upload.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,20 @@ qq.s3.XhrUploadHandler = function(spec, proxy) {
upload.track(id, xhr, chunkIdx).then(promise.success, promise.failure);
xhr.open("PUT", url, true);

var hasContentType = false;
qq.each(headers, function(name, val) {
if (name === "Content-Type") {
hasContentType = true;
}

xhr.setRequestHeader(name, val);
});

// Workaround for IE Edge
if (!hasContentType) {
xhr.setRequestHeader("Content-Type", "");
}

xhr.send(chunkData.blob);
}
}, function() {
Expand Down
2 changes: 1 addition & 1 deletion test/static/third-party/sinon/fake_xml_http_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
send: function send(data) {
verifyState(this);

if (!/^(get|head)$/i.test(this.method)) {
if (!/^(get|head|put)$/i.test(this.method)) {
if (this.requestHeaders["Content-Type"]) {
var value = this.requestHeaders["Content-Type"].split(";");
this.requestHeaders["Content-Type"] = value[0] + ";charset=utf-8";
Expand Down
16 changes: 16 additions & 0 deletions test/unit/s3/chunked-uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ if (qqtest.canDownloadFileAsBlob) {
assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=1&uploadId=123");
assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]);

assert.equal(uploadPartRequest.requestHeaders["Content-Type"], "");

var authParts = uploadPartRequest.requestHeaders.Authorization.split(";");
assert.equal(authParts.length, 3);
assert.equal(authParts[0].split(",")[1], "SignedHeaders=host");
Expand Down Expand Up @@ -189,6 +191,8 @@ if (qqtest.canDownloadFileAsBlob) {
assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=2&uploadId=123");
assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]);

assert.equal(uploadPartRequest.requestHeaders["Content-Type"], "");

var authParts = uploadPartRequest.requestHeaders.Authorization.split(";");
assert.equal(authParts.length, 3);
assert.equal(authParts[0].split(",")[1], "SignedHeaders=host");
Expand Down Expand Up @@ -343,6 +347,9 @@ if (qqtest.canDownloadFileAsBlob) {
assert.equal(uploadPartRequest.method, "PUT");
assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=1&uploadId=123");
assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]);

assert.equal(uploadPartRequest.requestHeaders["Content-Type"], "");

assert.equal(uploadPartRequest.requestHeaders.Authorization, "AWS " + testAccessKey + ":thesignature");
uploadPartRequest.respond(200, {ETag: "etag1"}, null);

Expand All @@ -364,6 +371,9 @@ if (qqtest.canDownloadFileAsBlob) {
assert.equal(uploadPartRequest.method, "PUT");
assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=2&uploadId=123");
assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]);

assert.equal(uploadPartRequest.requestHeaders["Content-Type"], "");

assert.equal(uploadPartRequest.requestHeaders.Authorization, "AWS " + testAccessKey + ":thesignature");
uploadPartRequest.respond(200, {ETag: "etag2"}, null);

Expand Down Expand Up @@ -800,6 +810,9 @@ if (qqtest.canDownloadFileAsBlob) {
assert.equal(uploadPartRequest.method, "PUT");
assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=1&uploadId=123");
assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]);

assert.equal(uploadPartRequest.requestHeaders["Content-Type"], "");

assert.equal(uploadPartRequest.requestHeaders.Authorization.indexOf("AWS " + testAccessKey + ":"), 0, "Upload part 1 request Authorization header is invalid");
uploadPartRequest.respond(200, {ETag: "etag1"}, null);

Expand All @@ -809,6 +822,9 @@ if (qqtest.canDownloadFileAsBlob) {
assert.equal(uploadPartRequest.method, "PUT");
assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=2&uploadId=123");
assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]);

assert.equal(uploadPartRequest.requestHeaders["Content-Type"], "");

assert.equal(uploadPartRequest.requestHeaders.Authorization.indexOf("AWS " + testAccessKey + ":"), 0, "Upload part 2 request Authorization header is invalid");
uploadPartRequest.respond(200, {ETag: "etag2"}, null);

Expand Down

0 comments on commit a060e50

Please sign in to comment.