Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我们如何在容器下创建子文件夹我的问题与此不同_Java_Azure_Azure Blob Storage - Fatal编程技术网

Java 我们如何在容器下创建子文件夹我的问题与此不同

Java 我们如何在容器下创建子文件夹我的问题与此不同,java,azure,azure-blob-storage,Java,Azure,Azure Blob Storage,我想将特定映像或配置文件存储在如下结构中: /test/images/abc.png /test/images1/abc.png 问题:我们如何在容器下创建子文件夹。在我的用例测试中,将有一个容器,图像将保存在文件夹中,图像和图像1将在存储abc.png文件时创建 在AWS中,它会自动创建这样的路径,我们可以直接存储 下面是我试图执行的代码。 CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionStri

我想将特定映像或配置文件存储在如下结构中:

/test/images/abc.png
/test/images1/abc.png

问题:我们如何在容器下创建子文件夹。在我的用例测试中,将有一个容器,图像将保存在文件夹中,图像和图像1将在存储abc.png文件时创建

在AWS中,它会自动创建这样的路径,我们可以直接存储

下面是我试图执行的代码。

CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient client = account.createCloudBlobClient();
CloudBlobContainer container = client.getContainerReference("test");
String key="images1/746ca358-2c6d-41f1-943e-a6a5ae287826.png";
CloudBlockBlob blob = container.getBlockBlobReference(key);

File sourceFile = new File("/Users/saurabhmishra/Desktop/error.png");
FileInputStream inputStream = new FileInputStream(sourceFile);
blob.upload(inputStream,100);
com.microsoft.azure.storage.StorageException: The specified blob does not exist.
    at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:87)
    at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305)
    at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:196)
    at com.microsoft.azure.storage.blob.CloudBlockBlob.uploadFullBlob(CloudBlockBlob.java:1035)
    at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:864)
    at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:743)
    at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:712)
    at quickstart.Test.upload(Test.java:54)
    at quickstart.Test.main(Test.java:23)

Process finished with exit code 0
我得到以下错误。

CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient client = account.createCloudBlobClient();
CloudBlobContainer container = client.getContainerReference("test");
String key="images1/746ca358-2c6d-41f1-943e-a6a5ae287826.png";
CloudBlockBlob blob = container.getBlockBlobReference(key);

File sourceFile = new File("/Users/saurabhmishra/Desktop/error.png");
FileInputStream inputStream = new FileInputStream(sourceFile);
blob.upload(inputStream,100);
com.microsoft.azure.storage.StorageException: The specified blob does not exist.
    at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:87)
    at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305)
    at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:196)
    at com.microsoft.azure.storage.blob.CloudBlockBlob.uploadFullBlob(CloudBlockBlob.java:1035)
    at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:864)
    at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:743)
    at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:712)
    at quickstart.Test.upload(Test.java:54)
    at quickstart.Test.main(Test.java:23)

Process finished with exit code 0
以下是一个示例:

    public static void main(String[] args) throws Exception {
        String connectionString = "DefaultEndpointsProtocol=https;AccountName=storagetest789;AccountKey=G3*****************************w==;EndpointSuffix=core.windows.net";
        StorageCredentials credentials = StorageCredentials.tryParseCredentials(connectionString);

        CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);
        CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
        CloudBlobContainer blobContainer = blobClient.getContainerReference("pub");
        blobContainer.createIfNotExists();

        CloudBlobDirectory subDirectory = blobContainer.getDirectoryReference("subDirectory1/subdirectory2/");
        CloudBlockBlob blockBlob = subDirectory.getBlockBlobReference("test.txt");
        blockBlob.uploadFromFile("D:\\User\\Desktop\\test.txt");

    }
基本上,您只需要使用
blobContainer.getDirectoryReference(“subDirectory1/subdirectory2/”)获取目录引用,则可以从中获取块blob引用


我觉得你的代码还可以。您是否在blob.upload(inputStream,100)上得到错误信息行?是的,我也知道line@SaurabhMishra你能检查一下我的答案看是否有用吗?谢谢,杰克,是的,这很有用,我已经做到了