Skip to content

Commit b4f1084

Browse files
authored
Merge pull request #231132 from diberry/diberry/0315-stor-ts
Storage - TS dev guide
2 parents b6b1c0c + f96f53e commit b4f1084

16 files changed

+1512
-0
lines changed

articles/storage/blobs/TOC.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,64 @@ items:
759759
href: storage-blob-properties-metadata-javascript.md
760760
- name: Use access tiers
761761
href: storage-blob-use-access-tier-javascript.md
762+
- name: TypeScript
763+
items:
764+
- name: Get started
765+
href: storage-blob-typescript-get-started.md
766+
- name: Authorize access from your application
767+
items:
768+
- name: Azure Active Directory
769+
items:
770+
- name: Overview
771+
href: /azure/developer/javascript/sdk/authentication/overview?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
772+
- name: Auth using developer service principals
773+
href: /azure/developer/javascript/sdk/authentication/local-development-environment-service-principal?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
774+
- name: Auth using developer accounts
775+
href: /azure/developer/javascript/sdk/authentication/local-development-environment-developer-account?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
776+
- name: Auth from Azure-hosted apps
777+
href: /azure/developer/javascript/sdk/authentication/azure-hosted-apps?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
778+
- name: Auth from on-premises apps
779+
href: /azure/developer/javascript/sdk/authentication/on-premises-apps?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
780+
- name: Work with SAS tokens
781+
items:
782+
- name: User delegation SAS
783+
href: storage-blob-create-user-delegation-sas-javascript.md
784+
- name: Service SAS
785+
href: sas-service-create-javascript.md
786+
- name: Account SAS
787+
href: storage-blob-account-delegation-sas-create-javascript.md
788+
- name: Container actions
789+
items:
790+
- name: Create a container
791+
href: storage-blob-container-create-typescript.md
792+
- name: Get container URL
793+
href: storage-blob-get-url-typescript.md
794+
- name: Delete and restore containers
795+
href: storage-blob-container-delete-typescript.md
796+
- name: List containers
797+
href: storage-blob-containers-list-typescript.md
798+
- name: Manage properties and metadata
799+
href: storage-blob-container-properties-metadata-typescript.md
800+
- name: Blob actions
801+
items:
802+
- name: Upload blobs
803+
href: storage-blob-upload-typescript.md
804+
- name: Get blob URL
805+
href: storage-blob-get-url-typescript.md
806+
- name: Download blobs
807+
href: storage-blob-download-typescript.md
808+
- name: Copy blobs
809+
href: storage-blob-copy-typescript.md
810+
- name: List blobs
811+
href: storage-blobs-list-typescript.md
812+
- name: Delete and restore blobs
813+
href: storage-blob-delete-typescript.md
814+
- name: Find blobs using tags
815+
href: storage-blob-tags-typescript.md
816+
- name: Manage blob properties and metadata
817+
href: storage-blob-properties-metadata-typescript.md
818+
- name: Use access tiers
819+
href: storage-blob-use-access-tier-typescript.md
762820
- name: Python
763821
items:
764822
- name: Get started
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Create a blob container with TypeScript
3+
titleSuffix: Azure Storage
4+
description: Learn how to create a blob container in your Azure Storage account using the JavaScript client library using TypeScript.
5+
author: pauljewellmsft
6+
7+
ms.service: storage
8+
ms.topic: how-to
9+
ms.date: 03/21/2023
10+
ms.author: pauljewell
11+
ms.subservice: blobs
12+
ms.devlang: typescript
13+
ms.custom: devx-track-ts, devguide-ts
14+
---
15+
16+
# Create a blob container with TypeScript
17+
18+
Blobs in Azure Storage are organized into containers. Before you can upload a blob, you must first create a container. This article shows how to create containers with the [Azure Storage client library for JavaScript](https://www.npmjs.com/package/@azure/storage-blob).
19+
20+
## Name a container
21+
22+
A container name must be a valid DNS name, as it forms part of the unique URI used to address the container or its blobs. Follow these rules when naming a container:
23+
24+
- Container names can be between 3 and 63 characters long.
25+
- Container names must start with a letter or number, and can contain only lowercase letters, numbers, and the dash (-) character.
26+
- Two or more consecutive dash characters aren't permitted in container names.
27+
28+
The URI for a container is in this format:
29+
30+
`https://myaccount.blob.core.windows.net/mycontainer`
31+
32+
## Create a container
33+
34+
35+
To create a container, create a [BlobServiceClient](storage-blob-typescript-get-started.md#create-a-blobserviceclient-object) object or [ContainerClient](storage-blob-typescript-get-started.md#create-a-containerclient-object) object, then use one of the following create methods:
36+
37+
- [BlobServiceClient.createContainer](/javascript/api/@azure/storage-blob/blobserviceclient#@azure-storage-blob-blobserviceclient-createcontainer)
38+
- [ContainerClient.create](/javascript/api/@azure/storage-blob/containerclient?#@azure-storage-blob-containerclient-create)
39+
- [ContainerClient.createIfNotExists](/javascript/api/@azure/storage-blob/containerclient#@azure-storage-blob-containerclient-createifnotexists)
40+
41+
42+
Containers are created immediately beneath the storage account. It's not possible to nest one container beneath another. An exception is thrown if a container with the same name already exists.
43+
44+
The following example creates a container asynchronously from the BlobServiceClient:
45+
46+
47+
:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/container-create.ts" id="snippet_create_container" :::
48+
49+
## Understand the root container
50+
51+
A root container, with the specific name `$root`, enables you to reference a blob at the top level of the storage account hierarchy. For example, you can reference a blob _without using a container name in the URI_:
52+
53+
`https://myaccount.blob.core.windows.net/default.html`
54+
55+
The root container must be explicitly created or deleted. It isn't created by default as part of service creation. The same code displayed in the previous section can create the root. The container name is `$root`.
56+
57+
## Resources
58+
59+
To learn more about creating a container using the Azure Blob Storage client library for JavaScript, see the following resources.
60+
61+
### REST API operations
62+
63+
The Azure SDK for JavaScript contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar JavaScript paradigms. The client library methods for creating a container use the following REST API operation:
64+
65+
- [Create Container](/rest/api/storageservices/create-container) (REST API)
66+
67+
### Code samples
68+
69+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/TypeScript/NodeJS-v12/dev-guide/container-create.ts)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Delete and restore a blob container with TypeScript
3+
titleSuffix: Azure Storage
4+
description: Learn how to delete and restore a blob container in your Azure Storage account using the JavaScript client library using TypeScript.
5+
services: storage
6+
author: pauljewellmsft
7+
ms.author: pauljewell
8+
9+
ms.service: storage
10+
ms.topic: how-to
11+
ms.date: 03/21/2023
12+
ms.subservice: blobs
13+
ms.devlang: TypeScript
14+
ms.custom: devx-track-ts, devguide-ts
15+
---
16+
17+
# Delete and restore a blob container with TypeScript
18+
19+
This article shows how to delete containers with the [Azure Storage client library for JavaScript](https://www.npmjs.com/package/@azure/storage-blob). If you've enabled [container soft delete](soft-delete-container-overview.md), you can restore deleted containers.
20+
21+
## Delete a container
22+
23+
To delete a container in TypeScript, create a BlobServiceClient or ContainerClient then use one of the following methods:
24+
25+
- BlobServiceClient.[deleteContainer](/javascript/api/@azure/storage-blob/blobserviceclient#@azure-storage-blob-blobserviceclient-deletecontainer#@azure-storage-blob-blobserviceclient-deletecontainer)
26+
- ContainerClient.[delete](/javascript/api/@azure/storage-blob/blobserviceclient#@azure-storage-blob-blobserviceclient-deletecontainer)
27+
- ContainerClient.[deleteIfExists](/javascript/api/@azure/storage-blob/blobserviceclient#@azure-storage-blob-containerclient-deleteifexists)
28+
29+
After you delete a container, you can't create a container with the same name for at *least* 30 seconds. Attempting to create a container with the same name will fail with HTTP error code 409 (Conflict). Any other operations on the container or the blobs it contains will fail with HTTP error code 404 (Not Found).
30+
31+
## Delete container with BlobServiceClient
32+
33+
The following example deletes the specified container. Use the BlobServiceClient to delete a container:
34+
35+
:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/containers-delete.ts" id="snippet_delete_container_immediately" :::
36+
37+
## Delete container with ContainerClient
38+
39+
The following example shows how to delete all of the containers whose name starts with a specified prefix using a [ContainerClient](storage-blob-typescript-get-started.md#create-a-containerclient-object).
40+
41+
:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/containers-delete.ts" id="snippet_deleteContainersWithPrefix":::
42+
43+
## Restore a deleted container
44+
45+
When container soft delete is enabled for a storage account, a container and its contents may be recovered after it has been deleted, within a retention period that you specify. You can restore a soft-deleted container using a [BlobServiceClient](storage-blob-typescript-get-started.md#create-a-blobserviceclient-object) object:
46+
47+
- BlobServiceClient.[undeleteContainer](/javascript/api/@azure/storage-blob/blobserviceclient#@azure-storage-blob-blobserviceclient-deletecontainert#@azure-storage-blob-blobserviceclient-undeletecontainer)
48+
49+
The following example finds a deleted container, gets the version ID of that deleted container, and then passes that ID into the **undeleteContainer** method to restore the container.
50+
51+
:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/containers-delete.ts" id="snippet_undeleteContainer":::
52+
53+
## Resources
54+
55+
To learn more about deleting a container using the Azure Blob Storage client library for JavaScript, see the following resources.
56+
57+
### REST API operations
58+
59+
The Azure SDK for JavaScript contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar JavaScript paradigms. The client library methods for deleting or restoring a container use the following REST API operations:
60+
61+
- [Delete Container](/rest/api/storageservices/delete-container) (REST API)
62+
- [Restore Container](/rest/api/storageservices/restore-container) (REST API)
63+
64+
### Code samples
65+
66+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/TypeScript/NodeJS-v12/dev-guide/containers-delete.ts)
67+
68+
[!INCLUDE [storage-dev-guide-resources-typescript](../../../includes/storage-dev-guides/storage-dev-guide-resources-typescript.md)]
69+
70+
### See also
71+
72+
- [Soft delete for containers](soft-delete-container-overview.md)
73+
- [Enable and manage soft delete for containers](soft-delete-container-enable.md)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: Manage container properties with TypeScript
3+
titleSuffix: Azure Storage
4+
description: Learn how to set and retrieve system properties and store custom metadata on blob containers in your Azure Storage account using the JavaScript client library using TypeScript.
5+
services: storage
6+
author: pauljewellmsft
7+
ms.author: pauljewell
8+
9+
ms.service: storage
10+
ms.topic: how-to
11+
ms.date: 03/21/2023
12+
13+
ms.devlang: typescript
14+
ms.custom: devx-track-ts, devguide-ts
15+
---
16+
17+
# Manage container properties and metadata with TypeScript
18+
19+
Blob containers support system properties and user-defined metadata, in addition to the data they contain. This article shows how to manage system properties and user-defined metadata with the [Azure Storage client library for JavaScript](https://www.npmjs.com/package/@azure/storage-blob).
20+
21+
## About properties and metadata
22+
23+
- **System properties**: System properties exist on each Blob storage resource. Some of them can be read or set, while others are read-only. Under the covers, some system properties correspond to certain standard HTTP headers. The Azure Storage client library for JavaScript maintains these properties for you.
24+
25+
- **User-defined metadata**: User-defined metadata consists of one or more name-value pairs that you specify for a Blob storage resource. You can use metadata to store additional values with the resource. Metadata values are for your own purposes only, and don't affect how the resource behaves.
26+
27+
Metadata name/value pairs are valid HTTP headers and should adhere to all restrictions governing HTTP headers. For more information about metadata naming requirements, see [Metadata names](/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#metadata-names).
28+
29+
## Retrieve container properties
30+
31+
To retrieve container properties, create a [ContainerClient](/javascript/api/@azure/storage-blob/containerclient) object then use the following method:
32+
33+
- ContainerClient.[getProperties](/javascript/api/@azure/storage-blob/containerclient#@azure-storage-blob-containerclient-getproperties) (returns [ContainerProperties](/javascript/api/@azure/storage-blob/containerproperties))
34+
35+
The following code example fetches a container's properties and writes the property values to a console window:
36+
37+
:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/container-set-properties-and-metadata.ts" id="snippet_getContainerProperties" :::
38+
39+
## Set and retrieve metadata
40+
41+
You can specify metadata as one or more name-value pairs container resource. To set metadata, create a [ContainerClient](/javascript/api/@azure/storage-blob/containerclient) object then use the following method:
42+
43+
- ContainerClient.[setMetadata](/javascript/api/@azure/storage-blob/containerclient#@azure-storage-blob-containerclient-setmetadata)
44+
45+
The following code example sets metadata on a container.
46+
47+
:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/container-set-properties-and-metadata.ts" id="snippet_setContainerMetadata" :::
48+
49+
To retrieve metadata, [get the container properties](#retrieve-container-properties) then use the returned **metadata** property.
50+
51+
- [ContainerClient.getProperties](/javascript/api/@azure/storage-blob/containerclient#@azure-storage-blob-containerclient-getproperties)
52+
53+
## Resources
54+
55+
To learn more about setting and retrieving container properties and metadata using the Azure Blob Storage client library for JavaScript, see the following resources.
56+
57+
### REST API operations
58+
59+
The Azure SDK for JavaScript contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar JavaScript paradigms. The client library methods for setting and retrieving properties and metadata use the following REST API operations:
60+
61+
- [Get Container Properties](/rest/api/storageservices/get-container-properties) (REST API)
62+
- [Set Container Metadata](/rest/api/storageservices/set-container-metadata) (REST API)
63+
- [Get Container Metadata](/rest/api/storageservices/get-container-metadata) (REST API)
64+
65+
The `getProperties` method retrieves container properties and metadata by calling both the [Get Blob Properties](/rest/api/storageservices/get-blob-properties) operation and the [Get Blob Metadata](/rest/api/storageservices/get-blob-metadata) operation.
66+
67+
### Code samples
68+
69+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/TypeScript/NodeJS-v12/dev-guide/container-set-properties-and-metadata.js)
70+
71+
[!INCLUDE [storage-dev-guide-resources-typescript](../../../includes/storage-dev-guides/storage-dev-guide-resources-typescript.md)]

0 commit comments

Comments
 (0)