import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
/**
* Azure Functions with Azure Blob trigger.
*/
public class BlobTriggerFunction {
/**
* This function will be invoked when a new or updated blob is detected at the specified path. The blob contents are provided as input to this function.
*
* @return
*/
@FunctionName("BlobTrigger-Java")
public void blobTriggerWhenUploadFile(
@BlobTrigger(name = "content", path = "data/{name}", dataType = "binary", connection = "StorageConnection") byte[] content,
@BindingName("name") String name,
final ExecutionContext context
) {
context.getLogger().info("Java Blob trigger function processed a blob. Name: " + name + "\n Size: " + content.length + " Bytes");
//String result=new String(content,StandardCharsets.UTF_8);
InputStream inputStream = new ByteArrayInputStream(content);
String result = null;
try {
result = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
context.getLogger().info("The upload file content is: " + result);
}
}
2条答案
按热度按时间j2cgzkjk1#
从示例文档(www.example.com)看起来非常简单https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob#trigger---java-example
内容以字节数组的形式传入。
gev0vcfq2#
获取文件内容的方法之一是
这是工作代码