【发布时间】:2020-02-08 02:32:50
【问题描述】:
我的问题很简单。如何将文件上传到 Azure 存储?
谢谢。
【问题讨论】:
-
你想上传什么? Azure Blob 还是 Azure 文件?
-
@George Chen,我要上传文件
标签: java spring-boot azure-storage
我的问题很简单。如何将文件上传到 Azure 存储?
谢谢。
【问题讨论】:
标签: java spring-boot azure-storage
下面的代码是我上传文件到根目录的测试,它使用Azure Storage SDK v8,如果你想使用最新版本的sdk,你可以使用这个Azure File SDK:@ 987654321@。它将向您展示如何使用 SDK,它还包含许多示例,这是upload sample。
final String storageConnectionString =
"DefaultEndpointsProtocol=http;" +
"AccountName=your storage account name;" +
"AccountKey=your storage connection key";
try {
// Use the CloudStorageAccount object to connect to your storage account
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the file client.
CloudFileClient fileClient = storageAccount.createCloudFileClient();
// Get a reference to the file share
CloudFileShare share = fileClient.getShareReference("windows");
//Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.getRootDirectoryReference();
// Define the path to a local file.
final String filePath = "C:\\Users\\georgec\\Documents\\test.json";
//Get a reference to the file you want to upload
CloudFile cloudFile = rootDir.getFileReference("test.json");
cloudFile.uploadFromFile(filePath);
}
【讨论】: