Azure功能 - 写入和读取blob文件 [英] Azure Function - writing and reading a blob file

查看:158
本文介绍了Azure功能 - 写入和读取blob文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对Azure很陌生。


$这是我的第一篇文章,请原谅我,如果我犯了一个错误。 b $ b

我创建了一个由ASA使用服务总线队列触发的函数。

我的数据被传递到函数中。



我想知道如何创建一个blob文件,文件名必须是特定于某个字符串的。



我会然后喜欢写入文件甚至读取文件。

是否有使用Azure函数写入和读取文件的示例?

谢谢



DJ

解决方案


是否有使用Azure函数写入和读取文件的示例?


要将Blob绑定到您的函数,您需要添加以下配置部分以实现功能。 JSON。如果你想读取和写入数据到blob,方向必须设置为'inout'。

  {
type:blob,
name:myBlob,
path:mycontainer / myblob.txt,
connection:your_azurestorage_connection_name,
direction:inout
}

之后,您可以添加一个
$ b

  public static async任务运行(CloudBlockBlob myBlob,TraceWriter日志)
{





因为CloudBlockBlob的类型并未默认导入到Azure函数,所以我们需要添加以下内容代码来导入它。

  #rMicrosoft.WindowsAzure.Storage
using Microsoft.WindowsAzure.Storage.Blob ;

最后,我们可以使用myBlob引用读取或写入数据到blob。将数据写入blob的示例。

  byte [] buffer = System.Text.Encoding.UTF8.GetBytes(hello world !); 
myBlob.UploadFromByteArray(buffer,0,buffer.Length);


This is my first post, pleas excuse me if i have made an errors.

I am very new to Azure.

I have created a function that is triggered by ASA using Service bus Queue.

My data is passed into the function.

I would like to know how i can create a blob file , the file name must be specific to a certain string.

I would then like to write to the file or even read from the file.

Are there any samples of writing and reading to files using Azure functions? I am correct i must use a binding process.

Thank You

DJ

解决方案

Are there any samples of writing and reading to files using Azure functions? I am correct i must use a binding process.

To bind Blob to your function, you need to add following configure section to function.json. The direction must be set to 'inout' if you want to read and write data to the blob.

{
  "type": "blob",
  "name": "myBlob",
  "path": "mycontainer/myblob.txt",
  "connection": "your_azurestorage_connection_name",
  "direction": "inout"
}

After that, you could add a parameter to your function named myBlob.

public static async Task Run(CloudBlockBlob myBlob, TraceWriter log)
{
}

Since the type of CloudBlockBlob is not default imported to Azure function, we need to add following code to import it.

#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Blob;

At the last, we can read or write data to the blob using the myBlob reference. Sample of writing data to the blob.

byte[] buffer = System.Text.Encoding.UTF8.GetBytes("hello world!");
myBlob.UploadFromByteArray(buffer, 0, buffer.Length);

这篇关于Azure功能 - 写入和读取blob文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆