Skip to content

Commit 73cba0e

Browse files
authored
Merge pull request #244339 from pauljewellmsft/pauljewell-access-tier-java
Add access tier article for Java
2 parents 2817e8a + 12db8e8 commit 73cba0e

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

articles/storage/blobs/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ items:
735735
href: storage-blob-lease-java.md
736736
- name: Manage blob properties and metadata
737737
href: storage-blob-properties-metadata-java.md
738+
- name: Set or change a blob's access tier
739+
href: storage-blob-use-access-tier-java.md
738740
- name: Generate a shared access signature (SAS)
739741
items:
740742
- name: Create a user delegation SAS for a blob

articles/storage/blobs/storage-blob-java-get-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,4 @@ The following guides show you how to use each of these classes to build your app
172172
| [Delete and restore](storage-blob-delete-java.md) | Delete blobs, and if soft-delete is enabled, restore deleted blobs. |
173173
| [Find blobs using tags](storage-blob-tags-java.md) | Set and retrieve tags as well as use tags to find blobs. |
174174
| [Manage properties and metadata (blobs)](storage-blob-properties-metadata-java.md) | Get and set properties and metadata for blobs. |
175+
| [Set or change a blob's access tier](storage-blob-use-access-tier-java.md) | Set or change the access tier for a block blob. |
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
title: Set or change a blob's access tier with Java
3+
titleSuffix: Azure Storage
4+
description: Learn how to set or change a blob's access tier in your Azure Storage account using the Java client library.
5+
services: storage
6+
author: pauljewellmsft
7+
ms.author: pauljewell
8+
9+
ms.service: storage
10+
ms.topic: how-to
11+
ms.date: 07/11/2023
12+
ms.subservice: blobs
13+
ms.devlang: java
14+
ms.custom: devx-track-java, devguide-java
15+
---
16+
17+
# Set or change a block blob's access tier with Java
18+
19+
This article shows how to set or change the access tier for a block blob using the [Azure Storage client library for Java](/java/api/overview/azure/storage-blob-readme).
20+
21+
## Prerequisites
22+
23+
This article doesn't detail the project setup process. To learn about setting up your project, including package installation, adding `import` directives, and authorizing a client object, see [Get Started with Azure Storage and Java](storage-blob-java-get-started.md). To see the `import` directives used in the code samples for this article, see [Code samples](#code-samples).
24+
25+
You also need the right permissions to set the blob's access tier. To learn more, see the authorization guidance for the following REST API operation:
26+
- [Set Blob Tier](/rest/api/storageservices/set-blob-tier#authorization)
27+
28+
[!INCLUDE [storage-dev-guide-about-access-tiers](../../../includes/storage-dev-guides/storage-dev-guide-about-access-tiers.md)]
29+
30+
> [!NOTE]
31+
> To set the access tier to `Cold` using Java, you must use a minimum [client library](/java/api/overview/azure/storage-blob-readme) version of 12.21.0.
32+
33+
## Set a blob's access tier during upload
34+
35+
You can set a blob's access tier on upload by using the [BlobUploadFromFileOptions](/java/api/com.azure.storage.blob.options.blobuploadfromfileoptions) class. The following code example shows how to set the access tier when uploading a blob:
36+
37+
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobUpload.java" id="Snippet_UploadBlobWithAccessTier":::
38+
39+
To learn more about uploading a blob with Java, see [Upload a blob with Java](storage-blob-upload-java.md).
40+
41+
## Change the access tier for an existing block blob
42+
43+
You can change the access tier of an existing block blob by using one of the following methods:
44+
45+
- [setAccessTier](/java/api/com.azure.storage.blob.specialized.blobclientbase#com-azure-storage-blob-specialized-blobclientbase-setaccesstier(com-azure-storage-blob-models-accesstier))
46+
- [setAccessTierWithResponse](/java/api/com.azure.storage.blob.specialized.blobclientbase#method-details)
47+
48+
The following code example shows how to change the access tier to Cool for an existing blob:
49+
50+
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobAccessTier.java" id="Snippet_ChangeAccessTier":::
51+
52+
If you're rehydrating an archived blob, use the [setAccessTierWithResponse](/java/api/com.azure.storage.blob.specialized.blobclientbase#method-details) method. Set the `tier` parameter to a valid [AccessTier](/java/api/com.azure.storage.blob.models.accesstier) value of `HOT`, `COOL`, `COLD`, or `ARCHIVE`. You can optionally set the `priority` parameter to a valid [RehydratePriority](/java/api/com.azure.storage.blob.models.rehydratepriority) value `HIGH` or `STANDARD`.
53+
54+
The following code example shows how to rehydrate an archived blob by changing the access tier to Hot:
55+
56+
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobAccessTier.java" id="Snippet_RehydrateUsingSetAccessTier":::
57+
58+
The [setAccessTierWithResponse](/java/api/com.azure.storage.blob.specialized.blobclientbase#method-details) method can also accept a [BlobSetAccessTierOptions](/java/api/com.azure.storage.blob.options.blobsetaccesstieroptions) parameter to specify configuration options.
59+
60+
## Copy a blob to a different access tier
61+
62+
You can change the access tier of an existing block blob by specifying an access tier as part of a copy operation. To change the access tier during a copy operation, use the [BlobBeginCopyOptions](/java/api/com.azure.storage.blob.options.blobbegincopyoptions) class.
63+
64+
You can use the [setTier](/java/api/com.azure.storage.blob.options.blobbegincopyoptions#com-azure-storage-blob-options-blobbegincopyoptions-settier(com-azure-storage-blob-models-accesstier)) method to specify the [AccessTier](/java/api/com.azure.storage.blob.models.accesstier) value as `HOT`, `COOL`, `COLD`, or `ARCHIVE`. If you're rehydrating a blob from the archive tier using a copy operation, use the [setRehydratePriority](/java/api/com.azure.storage.blob.options.blobbegincopyoptions#com-azure-storage-blob-options-blobbegincopyoptions-setrehydratepriority(com-azure-storage-blob-models-rehydratepriority)) method to specify the [RehydratePriority](/java/api/com.azure.storage.blob.models.rehydratepriority) value as `HIGH` or `STANDARD`.
65+
66+
The following code example shows how to rehydrate an archived blob to the Hot tier using a copy operation:
67+
68+
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobAccessTier.java" id="Snippet_RehydrateUsingCopy":::
69+
70+
To learn more about copying a blob with Java, see [Copy a blob with Java](storage-blob-copy-java.md).
71+
72+
## Resources
73+
74+
To learn more about setting access tiers using the Azure Blob Storage client library for Java, see the following resources.
75+
76+
### REST API operations
77+
78+
The Azure SDK for Java contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar Java paradigms. The client library methods for setting access tiers use the following REST API operation:
79+
80+
- [Set Blob Tier](/rest/api/storageservices/set-blob-tier) (REST API)
81+
82+
[!INCLUDE [storage-dev-guide-resources-java](../../../includes/storage-dev-guides/storage-dev-guide-resources-java.md)]
83+
84+
### Code samples
85+
86+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobAccessTier.java)
87+
88+
### See also
89+
90+
- [Access tiers best practices](access-tiers-best-practices.md)
91+
- [Blob rehydration from the Archive tier](archive-rehydrate-overview.md)

includes/storage-dev-guides/storage-dev-guide-about-access-tiers.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Azure Storage access tiers include:
2525

2626
To learn more about access tiers, see [Access tiers for blob data](../../articles/storage/blobs/access-tiers-overview.md).
2727

28+
While a blob is in the Archive access tier, it's considered to be offline, and can't be read or modified. In order to read or modify data in an archived blob, you must first rehydrate the blob to an online tier. To learn more about rehydrating a blob from the Archive tier to an online tier, see [Blob rehydration from the Archive tier](../../articles/storage/blobs/archive-rehydrate-overview.md).
29+
2830
#### Restrictions
2931

3032
Setting the access tier is only allowed on block blobs. To learn more about restrictions on setting a block blob's access tier, see [Set Blob Tier (REST API)](/rest/api/storageservices/set-blob-tier#remarks).

0 commit comments

Comments
 (0)