![](/img/trans.png)
[英]How to upload a file to Azure blob Storage by Apache Beam?
[英]How to read file changes in azure blob storage?
我正在尝试从 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();
}
}
我能够从 azure 文件存储中读取文件。 我正在尝试创建类似 Java WatchService 之类的东西,如果文件有任何更改,我想读取更改并打印数据,例如下面假设我在 blob 中有文件 test.txt 文件,最初它有如下数据
"Hello"
我的程序应该打印"Hello"
。
一段时间后,我将使用"world"
更新文件,现在我只想打印"world"
,这是文件中的新更改。
azure blob存储是否可以? 我看到了azure_blob_storage的azure_blob_storage
,但没有找到像java WatchServices这样的方法。 您能帮我如何读取 azure blob 存储中的文件更改吗?
没有这样的服务。 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.
这里是一步一步如何做到这一点:
https://docs.microsoft.com/en-us/azure/event-grid/blob-event-quickstart-portal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.