繁体   English   中英

如何将文件上传到 Azure 存储?

[英]How to upload a file to Azure storage?

我的问题很简单。 如何将文件上传到 Azure 存储?

谢谢你。

The below code is my test to upload a file to root directory, it uses Azure Storage SDK v8 , if you want to use the latest version sdk, you could use this Azure File SDK: Azure File client library for Java . 它将向您展示如何使用 SDK 并且它还包含许多示例,这是上传示例

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);
    }

暂无
暂无

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

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