Using Python, I am generating a SAS URL. An example of a generated SAS URL is:
https://testvideos.blob.core.windows.net/testvideos/user_125/video_125/test.mp4?se=2023-05-14T11%3A02%3A59Z&sp=rc&sv=2022-11-02&sr=b&sig=7o8tNK508ekXy9JpahWBsfdfsfPjdtjWwN6etNk%3D
To utilize this generated SAS URL, I am making a PUT request through React JS.
import React, { useState } from "react";
const uploadBlocks = async (file, sasUrl, blockIds) => {
const blockSize = 4 * 1024 * 1024; // Adjust the block size as needed
const totalBlocks = Math.ceil(file.size / blockSize);
const promises = [];
console.log("Uploading blocks...");
for (let i = 0; i < totalBlocks; i++) {
const blockId = blockIds[i];
console.log(blockId);
const start = i * blockSize;
const end = Math.min(start + blockSize, file.size);
const blockContent = file.slice(start, end);
const promise = fetch(`${sasUrl}&comp=block&blockid=${blockId}`, {
method: "PUT",
headers: {
"Content-Type": file.type,
"x-ms-blob-type": "BlockBlob",
},
body: blockContent,
});
promises.push(promise);
}
await Promise.all(promises);
console.log("Blocks uploaded successfully.");
};
const commitBlockList = async (sasUrl, blockIds) => {
const xmlPayload = `
<BlockList>
${blockIds.map((blockId) => `<Latest>${blockId}</Latest>`).join("\n")}
</BlockList>
`;
console.log("Committing block list...");
const response = await fetch(`${sasUrl}&comp=blocklist`, {
method: "PUT",
headers: {
"Content-Type": "application/xml",
"x-ms-blob-type": "BlockBlob",
},
body: xmlPayload,
});
if (response.ok) {
console.log("Block list committed successfully.");
} else {
throw new Error("Failed to commit block list");
}
};
// More code here...
However, during the file upload process, I encountered the following errors:
403 (This request is not authorized to perform this operation using this permission.)
Failed to commit block list. Please make sure the SAS URL is properly authorized and the value of the Authorization header is formed correctly, including the signature.
I believe there might be an issue with the authorization headers or SAS URLs. Can you help?