Skip to content

Latest commit

 

History

History
107 lines (61 loc) · 7.17 KB

File metadata and controls

107 lines (61 loc) · 7.17 KB
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

Set or change a block blob's access tier with 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]

Set up your environment

[!INCLUDE storage-dev-guide-project-setup-java]

Add import statements

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":::

Authorization

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.

Set a blob's access tier during upload

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.

Change the access tier for an existing block blob

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.

Copy a blob to a different access tier

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.

Resources

To learn more about setting access tiers using the Azure Blob Storage client library for Java, see the following resources.

Code samples

REST API operations

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:

[!INCLUDE storage-dev-guide-resources-java]

See also

[!INCLUDE storage-dev-guide-next-steps-java]