Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions sdk/storage/storage-blob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ For example, you can create following CORS settings for debugging. But please cu

The Azure Storage SDK for JavaScript provides low-level and high-level APIs.

- ServiceURL, ContainerURL and BlobURL objects provide the low-level API functionality and map one-to-one to the [Azure Storage Blob REST APIs](https://docs.microsoft.com/en-us/rest/api/storageservices/blob-service-rest-api).
- BlobServiceClient, ContainerClient and BlobClient objects provide the low-level API functionality and map one-to-one to the [Azure Storage Blob REST APIs](https://docs.microsoft.com/en-us/rest/api/storageservices/blob-service-rest-api).

- The high-level APIs provide convenience abstractions such as uploading a large stream to a block blob (using multiple PutBlock requests).

Expand All @@ -127,11 +127,11 @@ The Azure Storage SDK for JavaScript provides low-level and high-level APIs.
```javascript
const {
Aborter,
BlobURL,
BlockBlobURL,
ContainerURL,
ServiceURL,
StorageURL,
BlobClient,
BlobServiceClient,
BlockBlobClient,
ContainerClient,
StorageClient,
SharedKeyCredential,
AnonymousCredential,
TokenCredential
Expand All @@ -153,18 +153,18 @@ async function main() {
const anonymousCredential = new AnonymousCredential();

// Use sharedKeyCredential, tokenCredential or anonymousCredential to create a pipeline
const pipeline = StorageURL.newPipeline(sharedKeyCredential);
const pipeline = StorageClient.newPipeline(sharedKeyCredential);

// List containers
const serviceURL = new ServiceURL(
const blobServiceClient = new BlobServiceClient(
// When using AnonymousCredential, following url should include a valid SAS or support public access
`https://${account}.blob.core.windows.net`,
pipeline
);

let marker;
do {
const listContainersResponse = await serviceURL.listContainersSegment(
const listContainersResponse = await blobServiceClient.listContainersSegment(
Aborter.none,
marker
);
Expand All @@ -177,9 +177,9 @@ async function main() {

// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
const containerClient = ContainerClient.fromBlobServiceClient(blobServiceClient, containerName);

const createContainerResponse = await containerURL.create(Aborter.none);
const createContainerResponse = await containerClient.create(Aborter.none);
console.log(
`Create container ${containerName} successfully`,
createContainerResponse.requestId
Expand All @@ -188,9 +188,9 @@ async function main() {
// Create a blob
const content = "hello";
const blobName = "newblob" + new Date().getTime();
const blobURL = BlobURL.fromContainerURL(containerURL, blobName);
const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL);
const uploadBlobResponse = await blockBlobURL.upload(
const blobClient = BlobClient.fromContainerClient(containerClient, blobName);
const blockBlobClient = BlockBlobClient.fromBlobClient(blobClient);
const uploadBlobResponse = await blockBlobClient.upload(
Aborter.none,
content,
content.length
Expand All @@ -203,7 +203,7 @@ async function main() {
// List blobs
marker = undefined;
do {
const listBlobsResponse = await containerURL.listBlobFlatSegment(
const listBlobsResponse = await containerClient.listBlobFlatSegment(
Aborter.none,
marker
);
Expand All @@ -217,14 +217,14 @@ async function main() {
// Get blob content from position 0 to the end
// In Node.js, get downloaded data by accessing downloadBlockBlobResponse.readableStreamBody
// In browsers, get downloaded data by accessing downloadBlockBlobResponse.blobBody
const downloadBlockBlobResponse = await blobURL.download(Aborter.none, 0);
const downloadBlockBlobResponse = await blobClient.download(Aborter.none, 0);
console.log(
"Downloaded blob content",
await streamToString(downloadBlockBlobResponse.readableStreamBody)
);

// Delete container
await containerURL.delete(Aborter.none);
await containerClient.delete(Aborter.none);

console.log("deleted container");
}
Expand Down
32 changes: 16 additions & 16 deletions sdk/storage/storage-blob/samples/javascript/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const {
uploadFileToBlockBlob,
uploadStreamToBlockBlob,
Aborter,
BlobURL,
BlockBlobURL,
ContainerURL,
ServiceURL,
StorageURL
BlobClient,
BlobServiceClient,
BlockBlobClient,
ContainerClient,
StorageClient
} = require("../.."); // Change to "@azure/storage-blob" in your package

async function main() {
Expand All @@ -23,31 +23,31 @@ async function main() {
const accountSas = "";
const localFilePath = "";

const pipeline = StorageURL.newPipeline(new AnonymousCredential(), {
const pipeline = StorageClient.newPipeline(new AnonymousCredential(), {
// httpClient: MyHTTPClient, // A customized HTTP client implementing IHttpClient interface
// logger: MyLogger, // A customized logger implementing IHttpPipelineLogger interface
retryOptions: { maxTries: 4 }, // Retry options
telemetry: { value: "HighLevelSample V1.0.0" } // Customized telemetry string
});

const serviceURL = new ServiceURL(
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net${accountSas}`,
pipeline
);

// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
await containerURL.create(Aborter.none);
const containerClient = ContainerClient.fromBlobServiceClient(blobServiceClient, containerName);
await containerClient.create(Aborter.none);

// Create a blob
const blobName = "newblob" + new Date().getTime();
const blobURL = BlobURL.fromContainerURL(containerURL, blobName);
const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL);
const blobClient = BlobClient.fromContainerClient(containerClient, blobName);
const blockBlobClient = BlockBlobClient.fromBlobClient(blobClient);

// Parallel uploading with uploadFileToBlockBlob in Node.js runtime
// uploadFileToBlockBlob is only available in Node.js
await uploadFileToBlockBlob(Aborter.none, localFilePath, blockBlobURL, {
await uploadFileToBlockBlob(Aborter.none, localFilePath, blockBlobClient, {
blockSize: 4 * 1024 * 1024, // 4MB block size
parallelism: 20, // 20 concurrency
progress: ev => console.log(ev)
Expand All @@ -59,7 +59,7 @@ async function main() {
await uploadStreamToBlockBlob(
Aborter.timeout(30 * 60 * 1000), // Abort uploading with timeout in 30mins
fs.createReadStream(localFilePath),
blockBlobURL,
blockBlobClient,
4 * 1024 * 1024,
20,
{
Expand All @@ -72,7 +72,7 @@ async function main() {
// Uncomment following code in browsers because uploadBrowserDataToBlockBlob is only available in browsers
/*
const browserFile = document.getElementById("fileinput").files[0];
await uploadBrowserDataToBlockBlob(Aborter.none, browserFile, blockBlobURL, {
await uploadBrowserDataToBlockBlob(Aborter.none, browserFile, blockBlobClient, {
blockSize: 4 * 1024 * 1024, // 4MB block size
parallelism: 20, // 20 concurrency
progress: ev => console.log(ev)
Expand All @@ -86,7 +86,7 @@ async function main() {
await downloadBlobToBuffer(
Aborter.timeout(30 * 60 * 1000),
buffer,
blockBlobURL,
blockBlobClient,
0,
undefined,
{
Expand All @@ -98,7 +98,7 @@ async function main() {
console.log("downloadBlobToBuffer success");

// Delete container
await containerURL.delete(Aborter.none);
await containerClient.delete(Aborter.none);
console.log("deleted container");
}

Expand Down
34 changes: 17 additions & 17 deletions sdk/storage/storage-blob/samples/javascript/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

const {
Aborter,
BlobURL,
BlockBlobURL,
ContainerURL,
ServiceURL,
StorageURL,
BlobClient,
BlockBlobClient,
ContainerClient,
BlobServiceClient,
StorageClient,
SharedKeyCredential,
AnonymousCredential,
TokenCredential
Expand All @@ -30,18 +30,18 @@ async function main() {
const anonymousCredential = new AnonymousCredential();

// Use sharedKeyCredential, tokenCredential or anonymousCredential to create a pipeline
const pipeline = StorageURL.newPipeline(sharedKeyCredential);
const pipeline = StorageClient.newPipeline(sharedKeyCredential);

// List containers
const serviceURL = new ServiceURL(
const blobServiceClient = new BlobServiceClient(
// When using AnonymousCredential, following url should include a valid SAS or support public access
`https://${account}.blob.core.windows.net`,
pipeline
);

let marker;
do {
const listContainersResponse = await serviceURL.listContainersSegment(
const listContainersResponse = await blobServiceClient.listContainersSegment(
Aborter.none,
marker
);
Expand All @@ -54,9 +54,9 @@ async function main() {

// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
const containerClient = ContainerClient.fromBlobServiceClient(blobServiceClient, containerName);

const createContainerResponse = await containerURL.create(Aborter.none);
const createContainerResponse = await containerClient.create(Aborter.none);
console.log(
`Create container ${containerName} successfully`,
createContainerResponse.requestId
Expand All @@ -65,9 +65,9 @@ async function main() {
// Create a blob
const content = "hello";
const blobName = "newblob" + new Date().getTime();
const blobURL = BlobURL.fromContainerURL(containerURL, blobName);
const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL);
const uploadBlobResponse = await blockBlobURL.upload(
const blobClient = BlobClient.fromContainerClient(containerClient, blobName);
const blockBlobClient = BlockBlobClient.fromBlobClient(blobClient);
const uploadBlobResponse = await blockBlobClient.upload(
Aborter.none,
content,
content.length
Expand All @@ -80,7 +80,7 @@ async function main() {
// List blobs
marker = undefined;
do {
const listBlobsResponse = await containerURL.listBlobFlatSegment(
const listBlobsResponse = await containerClient.listBlobFlatSegment(
Aborter.none,
marker
);
Expand All @@ -94,14 +94,14 @@ async function main() {
// Get blob content from position 0 to the end
// In Node.js, get downloaded data by accessing downloadBlockBlobResponse.readableStreamBody
// In browsers, get downloaded data by accessing downloadBlockBlobResponse.blobBody
const downloadBlockBlobResponse = await blobURL.download(Aborter.none, 0);
const downloadBlockBlobResponse = await blobClient.download(Aborter.none, 0);
console.log(
"Downloaded blob content",
await streamToString(downloadBlockBlobResponse.readableStreamBody)
);

// Delete container
await containerURL.delete(Aborter.none);
await containerClient.delete(Aborter.none);

console.log("deleted container");
}
Expand All @@ -127,4 +127,4 @@ main()
})
.catch(err => {
console.log(err.message);
});
});
32 changes: 16 additions & 16 deletions sdk/storage/storage-blob/samples/typescript/advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
uploadFileToBlockBlob,
uploadStreamToBlockBlob,
Aborter,
BlobURL,
BlockBlobURL,
ContainerURL,
ServiceURL,
StorageURL
BlobClient,
BlockBlobClient,
ContainerClient,
ServiceClient,
StorageClient
} from "../.."; // Change to "@azure/storage-blob" in your package

async function main() {
Expand All @@ -22,31 +22,31 @@ async function main() {
const accountSas = "";
const localFilePath = "";

const pipeline = StorageURL.newPipeline(new AnonymousCredential(), {
const pipeline = StorageClient.newPipeline(new AnonymousCredential(), {
// httpClient: MyHTTPClient, // A customized HTTP client implementing IHttpClient interface
// logger: MyLogger, // A customized logger implementing IHttpPipelineLogger interface
retryOptions: { maxTries: 4 }, // Retry options
telemetry: { value: "HighLevelSample V1.0.0" } // Customized telemetry string
});

const serviceURL = new ServiceURL(
const serviceClient = new ServiceClient(
`https://${account}.blob.core.windows.net${accountSas}`,
pipeline
);

// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
await containerURL.create(Aborter.none);
const containerClient = ContainerClient.fromServiceClient(serviceClient, containerName);
await containerClient.create(Aborter.none);

// Create a blob
const blobName = "newblob" + new Date().getTime();
const blobURL = BlobURL.fromContainerURL(containerURL, blobName);
const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL);
const blobClient = BlobClient.fromContainerClient(containerClient, blobName);
const blockBlobClient = BlockBlobClient.fromBlobClient(blobClient);

// Parallel uploading with uploadFileToBlockBlob in Node.js runtime
// uploadFileToBlockBlob is only available in Node.js
await uploadFileToBlockBlob(Aborter.none, localFilePath, blockBlobURL, {
await uploadFileToBlockBlob(Aborter.none, localFilePath, blockBlobClient, {
blockSize: 4 * 1024 * 1024, // 4MB block size
parallelism: 20, // 20 concurrency
progress: ev => console.log(ev)
Expand All @@ -58,7 +58,7 @@ async function main() {
await uploadStreamToBlockBlob(
Aborter.timeout(30 * 60 * 1000), // Abort uploading with timeout in 30mins
fs.createReadStream(localFilePath),
blockBlobURL,
blockBlobClient,
4 * 1024 * 1024,
20,
{
Expand All @@ -71,7 +71,7 @@ async function main() {
// Uncomment following code in browsers because uploadBrowserDataToBlockBlob is only available in browsers
/*
const browserFile = document.getElementById("fileinput").files[0];
await uploadBrowserDataToBlockBlob(Aborter.none, browserFile, blockBlobURL, {
await uploadBrowserDataToBlockBlob(Aborter.none, browserFile, blockBlobClient, {
blockSize: 4 * 1024 * 1024, // 4MB block size
parallelism: 20, // 20 concurrency
progress: ev => console.log(ev)
Expand All @@ -85,7 +85,7 @@ async function main() {
await downloadBlobToBuffer(
Aborter.timeout(30 * 60 * 1000),
buffer,
blockBlobURL,
blockBlobClient,
0,
undefined,
{
Expand All @@ -97,7 +97,7 @@ async function main() {
console.log("downloadBlobToBuffer success");

// Delete container
await containerURL.delete(Aborter.none);
await containerClient.delete(Aborter.none);
console.log("deleted container");
}

Expand Down
Loading