0
votes

Since my backend is Beego(Golang) and Azure didn't provide Storage Service SDK for Go, I have to manually create my blob uploading procesure. Here is my workflow:

  1. With Dropzonejs as the frontend, user drags a file into browser to be uploaded.
  2. In the Dropzone addedfile handler, the client asks my backend to generate an auth sig with data like my storage account, file name/length, and other x-ms-headers.
  3. The auth sig returned and I trigger Dropzone to call XMLHttpRequest.send() to the URL of Azure Put blob API, with the auth sig.
  4. Azure returns error and I found my backend didn't compute the sig with content-type data.

AuthenticationFailedServer failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:daefeaf4-0001-0021-74d6-f4a4cf000000 Time:2016-08-12T20:16:35.5410039ZThe MAC signature found in the HTTP request 'xxxx' is not the same as any computed signature. Server used following string to sign: 'PUT

multipart/form-data; boundary=----WebKitFormBoundaryn9qZe6obJbXmk5Ko

x-ms-blob-type:BlockBlob x-ms-date:Fri, 12 Aug 2016 20:16:36 GMT x-ms-version:2015-12-11 /myaccount/user-files/id_hex/57116204071.pdf'.

The problem is the random string of boundary in content-type (multipart/form-data; boundary=----WebKitFormBoundaryn9qZe6obJbXmk5Ko) is randomly generated by the browser AFTER xmlhttprequest.send() (in step 3). How do I know what the boundary string will be BEFORE xmlhttprequest.send() (in step 2)?

1

1 Answers

0
votes

Have you try the solution at Issue#590, which seems to be the similar scenario with you, who wants to remove the multipart/form-data; boundary from header.

With the solution provided in this issue, similar with:

$("#dropzone").dropzone({
  url: "<url>",
  method: "PUT",
  headers: {"Authorization": auth,
            "x-ms-date":strTime,
            "x-ms-version": "2015-12-11"
    },
  sending: function(file, xhr) {
    var _send = xhr.send;
    xhr.send = function() {
      _send.call(xhr, file);
    };
  }
});