Skip to main content 首页 创作者 christophacham agent-skills-library azure-storage-blob-java
azure-storage-blob-java Build blob storage applications with Azure Storage Blob SDK for Java. Use when uploading, downloading, or managing files in Azure Blob Storage, working with containers, or implementing streaming da...
跳到安装 Skills Marketplace 发现并探索由社区构建的 Agent Skills
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/christophacham/agent-skills-library --skill azure-storage-blob-java命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
下载 Zip 下载中... 同仓库更多 Skills Expert service mesh architect specializing in Istio, Linkerd, and cloud-native networking patterns. Masters traffic management, security policies, observability integration, and multi-cluster mesh con
service-mesh-observability Implement comprehensive observability for service meshes including distributed tracing, metrics, and visualization. Use when setting up mesh monitoring, debugging latency issues, or implementing SL...
Expert guide for writing efficient GLSL shaders (Vertex/Fragment) for web and game engines, covering syntax, uniforms, and common effects.
christophacham
christophacham/agent-skills-library
打开 GitHub 仓库 name azure-storage-blob-java description Build blob storage applications with Azure Storage Blob SDK for Java. Use when uploading, downloading, or managing files in Azure Blob Storage, working with containers, or implementing streaming da... risk unknown source community date_added 2026-02-27
Azure Storage Blob SDK for Java
Build blob storage applications using the Azure Storage Blob SDK for Java.
Installation
<dependency >
<groupId > com.azure</groupId >
<artifactId > azure-storage-blob</artifactId >
<version > 12.33.0</version >
</dependency >
Client Creation
BlobServiceClient
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
BlobServiceClient serviceClient = new BlobServiceClientBuilder ()
.endpoint("<storage-account-url>" )
.sasToken("<sas-token>" )
.buildClient();
BlobServiceClient serviceClient = new BlobServiceClientBuilder ()
.connectionString("<connection-string>" )
.buildClient();
With DefaultAzureCredential import com.azure.identity.DefaultAzureCredentialBuilder;
BlobServiceClient serviceClient = new BlobServiceClientBuilder ()
.endpoint("<storage-account-url>" )
.credential(new DefaultAzureCredentialBuilder ().build())
.buildClient();
BlobContainerClient import com.azure.storage.blob.BlobContainerClient;
BlobContainerClient containerClient = serviceClient.getBlobContainerClient("mycontainer" );
BlobContainerClient containerClient = new BlobContainerClientBuilder ()
.connectionString("<connection-string>" )
.containerName("mycontainer" )
.buildClient();
BlobClient import com.azure.storage.blob.BlobClient;
BlobClient blobClient = containerClient.getBlobClient("myblob.txt" );
BlobClient blobClient = containerClient.getBlobClient("folder/subfolder/myblob.txt" );
BlobClient blobClient = new BlobClientBuilder ()
.connectionString("<connection-string>" )
.containerName("mycontainer" )
.blobName("myblob.txt" )
.buildClient();
Core Patterns
Create Container
serviceClient.createBlobContainer("mycontainer" );
BlobContainerClient container = serviceClient.createBlobContainerIfNotExists("mycontainer" );
containerClient.create();
containerClient.createIfNotExists();
Upload Data import com.azure.core.util.BinaryData;
String data = "Hello, Azure Blob Storage!" ;
blobClient.upload(BinaryData.fromString(data));
blobClient.upload(BinaryData.fromString(data), true );
Upload from File blobClient.uploadFromFile("local-file.txt" );
blobClient.uploadFromFile("local-file.txt" , true );
Upload from Stream import com.azure.storage.blob.specialized.BlockBlobClient;
BlockBlobClient blockBlobClient = blobClient.getBlockBlobClient();
try (ByteArrayInputStream dataStream = new ByteArrayInputStream (data.getBytes())) {
blockBlobClient.upload(dataStream, data.length());
}
Upload with Options import com.azure.storage.blob.models.BlobHttpHeaders;
import com.azure.storage.blob.options.BlobParallelUploadOptions;
BlobHttpHeaders headers = new BlobHttpHeaders ()
.setContentType("text/plain" )
.setCacheControl("max-age=3600" );
Map<String, String> metadata = Map.of("author" , "john" , "version" , "1.0" );
try (InputStream stream = new FileInputStream ("large-file.bin" )) {
BlobParallelUploadOptions options = new BlobParallelUploadOptions (stream)
.setHeaders(headers)
.setMetadata(metadata);
blobClient.uploadWithResponse(options, null , Context.NONE);
}
Upload if Not Exists import com.azure.storage.blob.models.BlobRequestConditions;
BlobParallelUploadOptions options = new BlobParallelUploadOptions (inputStream, length)
.setRequestConditions(new BlobRequestConditions ().setIfNoneMatch("*" ));
blobClient.uploadWithResponse(options, null , Context.NONE);
Download Data
BinaryData content = blobClient.downloadContent();
String text = content.toString();
blobClient.downloadToFile("downloaded-file.txt" );
Download to Stream try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream ()) {
blobClient.downloadStream(outputStream);
byte [] data = outputStream.toByteArray();
}
Download with InputStream import com.azure.storage.blob.specialized.BlobInputStream;
try (BlobInputStream blobIS = blobClient.openInputStream()) {
byte [] buffer = new byte [1024 ];
int bytesRead;
while ((bytesRead = blobIS.read(buffer)) != -1 ) {
}
}
Upload via OutputStream import com.azure.storage.blob.specialized.BlobOutputStream;
try (BlobOutputStream blobOS = blobClient.getBlockBlobClient().getBlobOutputStream()) {
blobOS.write("Data to upload" .getBytes());
}
List Blobs import com.azure.storage.blob.models.BlobItem;
for (BlobItem blobItem : containerClient.listBlobs()) {
System.out.println("Blob: " + blobItem.getName());
}
import com.azure.storage.blob.models.ListBlobsOptions;
ListBlobsOptions options = new ListBlobsOptions ().setPrefix("folder/" );
for (BlobItem blobItem : containerClient.listBlobs(options, null )) {
System.out.println("Blob: " + blobItem.getName());
}
List Blobs by Hierarchy import com.azure.storage.blob.models.BlobListDetails;
String delimiter = "/" ;
ListBlobsOptions options = new ListBlobsOptions ()
.setPrefix("data/" )
.setDetails(new BlobListDetails ().setRetrieveMetadata(true ));
for (BlobItem item : containerClient.listBlobsByHierarchy(delimiter, options, null )) {
if (item.isPrefix()) {
System.out.println("Directory: " + item.getName());
} else {
System.out.println("Blob: " + item.getName());
}
}
Delete Blob blobClient.delete();
blobClient.deleteIfExists();
import com.azure.storage.blob.models.DeleteSnapshotsOptionType;
blobClient.deleteWithResponse(DeleteSnapshotsOptionType.INCLUDE, null , null , Context.NONE);
Copy Blob import com.azure.storage.blob.models.BlobCopyInfo;
import com.azure.core.util.polling.SyncPoller;
SyncPoller<BlobCopyInfo, Void> poller = blobClient.beginCopy("<source-blob-url>" , Duration.ofSeconds(1 ));
poller.waitForCompletion();
blobClient.copyFromUrl("<source-blob-url>" );
Generate SAS Token import com.azure.storage.blob.sas.*;
import java.time.OffsetDateTime;
BlobSasPermission permissions = new BlobSasPermission ().setReadPermission(true );
OffsetDateTime expiry = OffsetDateTime.now().plusDays(1 );
BlobServiceSasSignatureValues sasValues = new BlobServiceSasSignatureValues (expiry, permissions);
String sasToken = blobClient.generateSas(sasValues);
BlobContainerSasPermission containerPermissions = new BlobContainerSasPermission ()
.setReadPermission(true )
.setListPermission(true );
BlobServiceSasSignatureValues containerSasValues = new BlobServiceSasSignatureValues (expiry, containerPermissions);
String containerSas = containerClient.generateSas(containerSasValues);
Blob Properties and Metadata import com.azure.storage.blob.models.BlobProperties;
BlobProperties properties = blobClient.getProperties();
System.out.println("Size: " + properties.getBlobSize());
System.out.println("Content-Type: " + properties.getContentType());
System.out.println("Last Modified: " + properties.getLastModified());
Map<String, String> metadata = Map.of("key1" , "value1" , "key2" , "value2" );
blobClient.setMetadata(metadata);
BlobHttpHeaders headers = new BlobHttpHeaders ()
.setContentType("application/json" )
.setCacheControl("max-age=86400" );
blobClient.setHttpHeaders(headers);
Lease Blob import com.azure.storage.blob.specialized.BlobLeaseClient;
import com.azure.storage.blob.specialized.BlobLeaseClientBuilder;
BlobLeaseClient leaseClient = new BlobLeaseClientBuilder ()
.blobClient(blobClient)
.buildClient();
String leaseId = leaseClient.acquireLease(60 );
leaseClient.renewLease();
leaseClient.releaseLease();
Error Handling import com.azure.storage.blob.models.BlobStorageException;
try {
blobClient.download(outputStream);
} catch (BlobStorageException e) {
System.out.println("Status: " + e.getStatusCode());
System.out.println("Error code: " + e.getErrorCode());
}
Proxy Configuration import com.azure.core.http.ProxyOptions;
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
import java.net.InetSocketAddress;
ProxyOptions proxyOptions = new ProxyOptions (
ProxyOptions.Type.HTTP,
new InetSocketAddress ("localhost" , 8888 ));
BlobServiceClient client = new BlobServiceClientBuilder ()
.endpoint("<endpoint>" )
.sasToken("<sas-token>" )
.httpClient(new NettyAsyncHttpClientBuilder ().proxy(proxyOptions).build())
.buildClient();
Environment Variables AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=https;AccountName=...
AZURE_STORAGE_ACCOUNT_URL=https://<account>.blob.core.windows.net
Trigger Phrases
"Azure Blob Storage Java"
"upload download blob"
"blob container SDK"
"storage streaming"
"SAS token generation"
"blob metadata properties"
When to Use This skill is applicable to execute the workflow or actions described in the overview.