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:
- With Dropzonejs as the frontend, user drags a file into browser to be uploaded.
- 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.
- The auth sig returned and I trigger Dropzone to call XMLHttpRequest.send() to the URL of Azure Put blob API, with the auth sig.
- Azure returns error and I found my backend didn't compute the sig with content-type data.
AuthenticationFailed
Server 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: 'PUTmultipart/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)?