mirror of
https://github.com/hanzoai/azure-sdk-for-js.git
synced 2026-10-30 19:51:51 +00:00
Resolves #31049 A few changes were needed here: 1. Upgrade jsdom to >= 19 in the JS sample, similar to https://github.com/Azure/azure-sdk-for-js/issues/20934 which fixed the TS sample 2. Update the sample to use a SAS URL so that it can be runnable 3. Remove usage of env vars, instead using the string directly and recommending passing a SAS URL from the server in production
28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
// Import the polyfill before importing @azure/storage-blob
|
|
import "./polyfill.worker";
|
|
|
|
// At this point, you should be able to import @azure/storage-blob without
|
|
// any errors. If you are missing a global dependency, we'll throw a descriptive error on import.
|
|
import { ContainerClient } from "@azure/storage-blob";
|
|
|
|
async function uploadToStorageBlob() {
|
|
// For example, in Azure public cloud, a container SAS URL has the form of
|
|
// `https://${account}.blob.core.windows.net/${containerName}?${sasToken}`
|
|
const containerSasUrl = ""; // <replace this empty string with your SAS URL>
|
|
|
|
if (!containerSasUrl) {
|
|
throw new Error("Please replace the placeholder value of containerSasUrl with your SAS URL.");
|
|
}
|
|
|
|
const data = "Hello, Web Workers!";
|
|
|
|
const containerClient = new ContainerClient(containerSasUrl);
|
|
const blockBlobClient = containerClient.getBlockBlobClient("sample.txt");
|
|
|
|
await blockBlobClient.upload(data, data.length);
|
|
|
|
postMessage("Successfully uploaded 'sample.txt' to Azure Storage Blob!");
|
|
}
|
|
|
|
uploadToStorageBlob().catch((err) => console.error(err));
|