| title | Set or change a blob's access tier with Java |
|---|---|
| titleSuffix | Azure Storage |
| description | Learn how to set or change a blob's access tier in your Azure Storage account using the Java client library. |
| services | storage |
| author | stevenmatthew |
| ms.author | shaas |
| ms.service | azure-blob-storage |
| ms.topic | how-to |
| ms.date | 08/05/2024 |
| ms.devlang | java |
| ms.custom | devx-track-java, devguide-java, devx-track-extended-java |
[!INCLUDE storage-dev-guide-selector-access-tier]
This article shows how to set or change the access tier for a block blob using the Azure Storage client library for Java.
[!INCLUDE storage-dev-guide-prereqs-java]
[!INCLUDE storage-dev-guide-project-setup-java]
Add the following import statements:
:::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_Imports":::
The authorization mechanism must have the necessary permissions to set a blob's access tier. For authorization with Microsoft Entra ID (recommended), you need Azure RBAC built-in role Storage Blob Data Contributor or higher. To learn more, see the authorization guidance for Set Blob Tier.
[!INCLUDE storage-dev-guide-create-client-java]
[!INCLUDE storage-dev-guide-about-access-tiers]
Note
To set the access tier to Cold using Java, you must use a minimum client library version of 12.21.0.
You can set a blob's access tier on upload by using the BlobUploadFromFileOptions class. The following code example shows how to set the access tier when uploading a blob:
:::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":::
To learn more about uploading a blob with Java, see Upload a blob with Java.
You can change the access tier of an existing block blob by using one of the following methods:
The following code example shows how to change the access tier to Cool for an existing blob:
:::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":::
If you're rehydrating an archived blob, use the setAccessTierWithResponse method. Set the tier parameter to a valid AccessTier value of HOT, COOL, COLD, or ARCHIVE. You can optionally set the priority parameter to a valid RehydratePriority value HIGH or STANDARD.
The following code example shows how to rehydrate an archived blob by changing the access tier to Hot:
:::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":::
The setAccessTierWithResponse method can also accept a BlobSetAccessTierOptions parameter to specify configuration options.
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 class.
You can use the setTier method to specify the 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 method to specify the RehydratePriority value as HIGH or STANDARD.
The following code example shows how to rehydrate an archived blob to the Hot tier using a copy operation:
:::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":::
To learn more about copying a blob with Java, see Copy a blob with Java.
To learn more about setting access tiers using the Azure Blob Storage client library for Java, see the following resources.
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:
- Set Blob Tier (REST API)
[!INCLUDE storage-dev-guide-resources-java]
[!INCLUDE storage-dev-guide-next-steps-java]