I'm currently trying to get data from Azure Blob Storage in to my Flask application. By doing this, I'm using the JavaScript SDK v12 for Browser.
I run in to problems when running the code, and it says in the console:
Uncaught Error: Module name "@azure/storage-blob" has not been loaded yet for context: _. Use require([]) https://requirejs.org/docs/errors.html#notloaded at makeError (require.js:5) at Object.s [as require] (require.js:5) at requirejs (require.js:5) at java.js:1
The code (got a bit messed up with indents)
const { BlobServiceClient } = require("@azure/storage-blob");
const containerName = "danicontainer";
const blobName = "Blobname foo";
const connStr = "ConnectionString foo";
const blobServiceClient = BlobServiceClient.fromConnectionString(connStr);
async function main() {
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobClient = containerClient.getBlobClient(blobName);
// Get blob content from position 0 to the end
// In browsers, get downloaded data by accessing downloadBlockBlobResponse.blobBody
const downloadBlockBlobResponse = await blobClient.download();
const downloaded = await blobToString(await downloadBlockBlobResponse.blobBody);
console.log("Downloaded blob content", downloaded);
// [Browsers only] A helper method used to convert a browser Blob into string.
async function blobToString(blob) {
const fileReader = new FileReader();
return new Promise((resolve, reject) => {
fileReader.onloadend = (ev) => {
resolve(ev.target.result);
};
fileReader.onerror = reject;
fileReader.readAsText(blob);
});
}
document.write("Finished!");
document.write(downloaded);
}
main();
console.log("Test");
Together with this, we have the require.js file as well as a html/python file for Flask.