Reputation: 1635
After much pain and suffering I was finally able to get a 2xx status code from the Azure Blog Storage API on an upload request. I am not sure why this is so difficult when to compared to AWS S3.
Here is the code that I am using to upload a voice recording:
var blockId = btoa("Test");
$.ajax({
url: `https://${app}.blob.core.windows.net/blob/test.mp3?comp=block&blockid=${blockId}&${sas}`,
type: 'PUT',
contentType: 'audio/mpeg',
data: audio.audioBlob,
processData: false,
headers: {
'x-ms-blob-type': 'BlockBlob',
'x-ms-date': new Date().toGMTString(),
'x-ms-version': '2020-02-10'
}
});
I am not sure if it matters, but I am using the following Chrome command to bypass CORS from my local machine.
chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
I did try to enable CORS in the Azure Portal by setting the following values, yet that did not work.
I was so excited I got a 2xx status code that I jumped to the Azure Portal. Unfortunately my file was not there. I thought it may be asynchronous so I waited 10 minutes. The recording I sent was only 5 seconds long so I'm certain it would not take longer than that.
Do you know what's happening here?
Upvotes: 1
Views: 4644
Reputation: 136356
Do you know what's happening here?
I noticed that you're doing a chunked upload. Essentially you're performing Put Block
operation (instead of Put Blob
operation). 201
status code essentially tells you that the block (chunk) you uploaded reached storage successfully.
What you would need to do next is call Put Block List
operation by including ids of all the blocks you uploaded. This will tell Azure Storage to stitch those blocks together and save them as blob.
Upvotes: 1