我们如何强制性地绑定到输入Blob?
我希望能够读取我的azure函数内部的blob。一种方法是添加像这样的参数:
[Blob("%MyInputBlob%/{FileName}", FileAccess.Read)] Stream input
但是,这对我不起作用,因为我需要读取多个blob,并且它们具有不同的{filenames}
。
我知道有一种命令式绑定解决方案可以像这样写输出:
var attributes = new Attribute[]
{
new BlobAttribute(path),
new StorageAccountAttribute(connection)
};
using (var writer = await binder.BindAsync<TextWriter>(attributes))
{
writer.Write(payload);
}
对INPUT Blob是否具有类似的绑定功能?
答案 0 :(得分:1)
对于动态输入绑定,您可以如下更改绑定类型:
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enetr the number of Student");
int totalStudent = sc.nextInt();
Map<Integer, Map<String, Student>> map = new TreeMap<>();
for(int i =0;i<totalStudent;i++) {
Student ss = new Student();
System.out.println("Enter the Student roll number");
ss.setRollNumber(sc.nextInt());
System.out.println("Enter the Student Name");
ss.setName(sc.next());
System.out.println("Enter the m1 marks ");
ss.setM1(sc.nextInt());
System.out.println("Enetr the m2 marks ");
ss.setM2(sc.nextInt());
System.out.println("Enter the m3 marks ");
ss.setM3(sc.nextInt());
ss.setTotMarks(ss.getM1()+ss.getM2()+ss.getM3());
Integer key = ss.getTotMarks();
if (map.get(key) == null){ // if this is a new key in the map, then create a new TreeMap and put it
final TreeMap<String, Student> nameAndStudentMap = new TreeMap<>();
nameAndStudentMap.put(ss.getName(), ss);
map.put(key, nameAndStudentMap);
}else { // if the key already existed, then get the map stored and add to it.
map.get(key).put(ss.getName(), ss);
}
}
//stdList.forEach(System.out::print);
for(Map.Entry<Integer,Map<String, Student>> m :map.entrySet()) {
for (Map.Entry<String, Student> nameAndStudent : m.getValue().entrySet()) {
System.out.println(m.getKey() + " = " + nameAndStudent.getValue());
}
}
}
这里是您可以参考的类似issue。
答案 1 :(得分:1)
如果我对您的理解正确-您可以在不指定文件名的情况下获得对blob容器的引用:
[Blob("ContainerName", Connection = "StorageConnectionString")] CloudBlobContainer container
然后从这里-读取文件:
container.GetBlockBlobReference("filename");