英文:
How to copy Azure storage files/directories using java azure-storage-file-datalake
问题
我使用 azure-storage-file-datalake 来进行Java编程,以便在我的Azure存储账户上执行文件系统操作,我可以打开文件,删除文件,甚至重命名/移动文件或目录。
我找不到任何复制文件/文件夹到其他位置的方法。
以下是如何重命名/移动文件或目录的示例代码:
DataLakeServiceClient storageClient = new DataLakeServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();
DataLakeFileSystemClient dataLakeFileSystemClient = storageClient.getFileSystemClient("storage");
DataLakeFileClient fileClient = dataLakeFileSystemClient.getFileClient("src/path");
fileClient.rename("storage", "dest/path");
是否有其他方法可以使用 azure-storage-file-datalake
SDK 或者 azure-storage-blob
SDK 来复制文件或目录?
英文:
I use azure-storage-file-datalake for java to make file system operations on my Azure storage account, I can open files, delete, and even rename/move files or directories.
I can't find any way to copy files/folder to other location.
That's how I rename/move files/directories:
DataLakeServiceClient storageClient = new DataLakeServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();
DataLakeFileSystemClient dataLakeFileSystemClient = storageClient.getFileSystemClient("storage");
DataLakeFileClient fileClient = dataLakeFileSystemClient.getFileClient("src/path");
fileClient.rename("storage", "dest/path");
Is there any other method I can use to copy files or directories using the azure-storage-file-datalake
SDK or even the azure-storage-blob
SDK?
答案1
得分: 1
我找到了一种在同一存储账户内使用 com.azure.storage.blob.BlobClient
复制块(blob/文件)的方法。
使用 beginCopy
方法,如下所示:
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().endpoint(spnEndpoint).credential(credential).buildClient();
BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient("containerName");
BlobClient dst = blobContainerClient.getBlobClient("destination/blob");
BlobClient src = blobContainerClient.getBlobClient("src/blob");
dst.beginCopy(src.getBlobUrl(), null);
英文:
I found a method to copy blobs(files) within the same storage account using com.azure.storage.blob.BlobClient
.
using beginCopy
method as follows:
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().endpoint(spnEndpoint).credential(credential).buildClient();
BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient("containerName");
BlobClient dst = blobContainerClient.getBlobClient("destination/blob");
BlobClient src = blobContainerClient.getBlobClient("src/blob");
dst.beginCopy(src.getBlobUrl(), null);
答案2
得分: 0
你可以使用 azure-sdk-for-java 来复制文件:
String CONNECT_STRING = "DefaultEndpointsProtocol=https;AccountName=<account-name>;AccountKey=<account key>;EndpointSuffix=core.windows.net";
String SHARE_NAME = "share-name";
ShareFileClient client = new ShareFileClientBuilder()
.connectionString(CONNECT_STRING)
.shareName(SHARE_NAME)
.resourcePath("path/to/target/file.txt")
.buildFileClient();
String srcFile = "https://<account-name>.file.core.windows.net/share-name/path/to/source/file.txt";
SyncPoller<ShareFileCopyInfo, Void> poller = client.beginCopy(srcFile, null, Duration.ofSeconds(2));
final PollResponse<ShareFileCopyInfo> pollResponse = poller.poll();
final ShareFileCopyInfo value = pollResponse.getValue();
System.out.printf("Copy source: %s. Status: %s.%n", value.getCopySourceUrl(), value.getCopyStatus());
上述示例使用连接字符串来创建文件客户端,你也可以使用 SAS 令牌来创建文件客户端,详见 Java 文档 ShareFileClientBuilder。连接字符串和/或 SAS 令牌均可在 Azure 门户中的存储账户页面中找到。
英文:
You can use azure-sdk-for-java to copy file
String CONNECT_STRING = "DefaultEndpointsProtocol=https;AccountName=<account-name>;AccountKey=<account key>;EndpointSuffix=core.windows.net";
String SHARE_NAME = "share-name";
ShareFileClient client = new ShareFileClientBuilder()
.connectionString(CONNECT_STRING)
.shareName(SHARE_NAME)
.resourcePath("path/to/target/file.txt")
.buildFileClient();
String srcFile = "https://<account-name>.file.core.windows.net/share-name/path/to/source/file.txt";
SyncPoller<ShareFileCopyInfo, Void> poller = client.beginCopy(srcFile, null, Duration.ofSeconds(2));
final PollResponse<ShareFileCopyInfo> pollResponse = poller.poll();
final ShareFileCopyInfo value = pollResponse.getValue();
System.out.printf("Copy source: %s. Status: %s.%n", value.getCopySourceUrl(), value.getCopyStatus());
The above example uses connect string to create file client, you can also use SAS token to create file client, see java doc ShareFileClientBuilder for details. Both connect string and/or SAS token are available on your storage account page in azure portal.
答案3
得分: -1
azure-storage-file-datalake:
azure-storage-blob
这似乎没有可实现此的方法。
英文:
azure-storage-file-datalake:
azure-storage-blob
This seems not to have a method to achieve this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论