Commit b255fb4f authored by Abdullah Danish's avatar Abdullah Danish

AFP-000: adds file reading logic

parent adda896c
......@@ -2,6 +2,14 @@ package com.nisum.demo.blobStorage;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.regex.Pattern;
/**
* Azure Functions with Azure Blob trigger.
......@@ -12,10 +20,22 @@ public class BlobTriggerFunction {
*/
@FunctionName("BlobTriggerFunc")
public void run(
@BlobTrigger(name = "file", path = "test/{name}", dataType = "binary", connection = "MyStorageConnectionAppSetting") byte[] content,
@BlobTrigger(name = "file", path = "test/{name}", dataType = "binary", connection = "AzureWebJobsStorage") byte[] content,
@BindingName("name") String name,
final ExecutionContext context
) {
) throws IOException {
ResourceBundle resourceBundle = new PropertyResourceBundle(new FileInputStream("/Users/adanish/Documents/azure-function-blob-storage-examples/src/main/resources/application.properties"));
if (Pattern.matches("[a-z|A-Z]*.csv", name)) {
String directoryPath = resourceBundle.getString("files.directory.path")+name;
if (!Files.exists(Paths.get(directoryPath))) {
Files.createFile(Paths.get(directoryPath));
}
try (FileOutputStream fileOutputStream = new FileOutputStream(directoryPath, true)) {
fileOutputStream.write(content);
}
}
context.getLogger().info("Java Blob trigger function processed a blob. Name: " + name + "\n Size: " + content.length + " Bytes");
}
}
files.directory.path = /Users/adanish/Documents/azure-function-blob-storage-examples/src/main/resources/files/
\ No newline at end of file
hey there blob trigger function.hey there blob trigger function.hey there blob trigger function.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment