繁体   English   中英

使用 Java 将文件上传到 Azure Blob 存储

[英]Upload a file to Azure Blob storage using Java

如何使用 Azure Java SDK 将文件上传到 Azure Blob 存储并在上传文件后打印时间戳?

我在我的环境中尝试并在 azure blob 存储中成功上传了带有时间戳的文件:

代码:

package  com.blobs.quickstart;
import  org.apache.commons.lang3.time.StopWatch;
import  com.azure.storage.blob.*;
import  com.azure.storage.blob.BlobServiceClient;

public  class  App
{
public  static  void  main( String[] args )
{
String  connectStr = "< Connection string >";
BlobServiceClient  blobServiceClient = new  BlobServiceClientBuilder().connectionString(connectStr).buildClient();
String  containerName = "test";
BlobContainerClient  containerClient = blobServiceClient.getBlobContainerClient(containerName);
String  localPath = "path of your file";
BlobClient  blobClient = containerClient.getBlobClient("barcode.docx");
StopWatch  watch = new  StopWatch();
watch.start();
System.out.println("\nUploading to Blob storage as blob:\n\t" + blobClient.getBlobUrl());
blobClient.uploadFromFile(localPath);
watch.stop();
System.out.println("Time Elapsed: " + watch.getTime());
}
}

安慰:

在此处输入图像描述

门户网站:

在此处输入图像描述

参考: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-java?tabs=powershell%2Cmanaged-identity%2Croles-azure-portal%2Csign-in-azure-客户端

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM