简体   繁体   English

如何读取 azure blob 存储中的文件更改?

[英]How to read file changes in azure blob storage?

I am trying to read a file from azure blob storage as byte stream as below:我正在尝试从 azure blob 存储中读取文件作为字节 stream 如下:

    public static final String storageConnectionString =
            "DefaultEndpointsProtocol=https;AccountName=*;AccountKey=*;EndpointSuffix=core.windows.net";

    public static void main(String[] args) {
        try {
            CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
            CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
            CloudBlobContainer container = blobClient.getContainerReference("inputfile");
            CloudBlob blob = container.getBlockBlobReference("test.txt");
            InputStream input =  blob.openInputStream();
            InputStreamReader inr = new InputStreamReader(input, "UTF-8");
            String output = IOUtils.toString(inr);
            System.out.println(output);

            System.out.println("read is success");

        } catch (Exception e) {
            // Output the stack trace.
            e.printStackTrace();
        }
    }

I am able to read the file from azure file storage.我能够从 azure 文件存储中读取文件。 I am trying to create something like Java WatchService where if there is any change in file i want read the changes and print data for example below let say i have file test.txt file in blob initially it have data some thing like below我正在尝试创建类似 Java WatchService 之类的东西,如果文件有任何更改,我想读取更改并打印数据,例如下面假设我在 blob 中有文件 test.txt 文件,最初它有如下数据

"Hello"

My program should print "Hello" .我的程序应该打印"Hello"

After some time i will update file with "world" , now i want to print only "world" which is a new change in file.一段时间后,我将使用"world"更新文件,现在我只想打印"world" ,这是文件中的新更改。

Is it possible in azure blob storage? azure blob存储是否可以? I saw the API of azure_blob_storage but didn't find any method like java WatchServices.我看到了azure_blob_storage的azure_blob_storage ,但没有找到像java WatchServices这样的方法。 Could you please help me how can i read file changes in azure blob storage?您能帮我如何读取 azure blob 存储中的文件更改吗?

There's no such service.没有这样的服务。 However, you can use Event Grid which is an event repository, and subscribe to changes in your Azure storage account (new / updates blobs), then, trigger some function (maybe an Azure Function) to return the changes to client. However, you can use Event Grid which is an event repository, and subscribe to changes in your Azure storage account (new / updates blobs), then, trigger some function (maybe an Azure Function) to return the changes to client.

在此处输入图像描述

And here's a step by step how to do it:这里是一步一步如何做到这一点:

https://docs.microsoft.com/en-us/azure/event-grid/blob-event-quickstart-portal https://docs.microsoft.com/en-us/azure/event-grid/blob-event-quickstart-portal

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

相关问题 如何通过 Apache Beam 将文件上传到 Azure blob Storage? - How to upload a file to Azure blob Storage by Apache Beam? 如何生成 SAS 令牌并使用它将文件上传到 Azure Blob 存储? - How to generate a SAS token and use it to upload a file to Azure Blob Storage? 从 Azure Blob 存储读取和写入 excel 文件,无需将其下载到 Java 中的本地文件 - Read and write an excel file from Azure Blob Storage without downloading it to local file in Java 在Azure Blob存储中的文件上运行ffprobe - Running ffprobe on file lying in Azure Blob storage 如何使用 ManagedIdentityCredential 连接到 Azure Blob 存储 - How to connect to Azure Blob Storage using ManagedIdentityCredential 无法读取上传到Azure Blob的文件 - Not able to read file uploaded into Azure Blob PDF 到 Azure Blob 存储 - PDF to Azure Blob storage 如何在 Java 中将 AppendBlob/大于 4mb 限制的文件上传到 Azure 存储/Blob? - How to upload AppendBlob/a file larger than the 4mb limit into Azure Storage/Blob in Java? 如何使用 java 代码将文件作为 blob 从 Internet 上传到 Azure 存储? - How to upload a file from internet to azure storage as a blob using java code? 如何使用 java sdk 在 Azure Blob 存储中上传单个视频文件的多个块? - How to upload multiple chunks of a single video file in Azure Blob Storage using java sdk?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM