|
| 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) |
0 commit comments