我可以将输出绑定从 BLOB 存储更改为 Azure 函数中的文件共享存储吗?
Can I change the output binding from BLOB storage to File sharing storage in Azure function?
我有一个 Azure HTTP 触发器 POST 函数。当它收到 POST 请求时,它会将数据插入文本文件并将其存储在 Azure BLOB 存储中。我想将该文件存储到文件共享存储而不是 BLOB 存储中。我没有在函数的输出绑定中使用 Azure 文件共享存储。有可能吗?
run.csx
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
using System.Net;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage.Blob;
public static async Task<IActionResult> Run(HttpRequest req, CloudBlockBlob outputBlob)
{
var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
await outputBlob.UploadTextAsync(requestBody);
}
function.json
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"type": "blob",
"name": "outputBlob",
"path": "customers/CUST_{DateTime}.txt",
"connection": "AzureWebJobsStorage",
"direction": "out"
}
]
}
据我所知,目前Azure函数不支持Azure文件共享输出绑定。你可以参考这个教程:https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#binding-direction
但是你也可以使用 Azure 文件存储 sdk 来做到这一点,我 post 下面的一些代码供你参考:
var storageAccount = CloudStorageAccount.Parse("your connection string");
var fileClient = storageAccount.CreateCloudFileClient();
string baseShareName = "myazurefileshare";
var share = fileClient.GetShareReference(baseShareName);
var rootDir = share.GetRootDirectoryReference();
var sampleDir = rootDir.GetDirectoryReference("MyFolder");
var fileToCreate = sampleDir.GetFileReference("output.txt");
fileToCreate.UploadText(".....");
有关Azure File Share(.Net)的更多信息,请参考此教程:https://docs.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files
我有一个 Azure HTTP 触发器 POST 函数。当它收到 POST 请求时,它会将数据插入文本文件并将其存储在 Azure BLOB 存储中。我想将该文件存储到文件共享存储而不是 BLOB 存储中。我没有在函数的输出绑定中使用 Azure 文件共享存储。有可能吗?
run.csx
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
using System.Net;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage.Blob;
public static async Task<IActionResult> Run(HttpRequest req, CloudBlockBlob outputBlob)
{
var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
await outputBlob.UploadTextAsync(requestBody);
}
function.json
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"type": "blob",
"name": "outputBlob",
"path": "customers/CUST_{DateTime}.txt",
"connection": "AzureWebJobsStorage",
"direction": "out"
}
]
}
据我所知,目前Azure函数不支持Azure文件共享输出绑定。你可以参考这个教程:https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#binding-direction
但是你也可以使用 Azure 文件存储 sdk 来做到这一点,我 post 下面的一些代码供你参考:
var storageAccount = CloudStorageAccount.Parse("your connection string");
var fileClient = storageAccount.CreateCloudFileClient();
string baseShareName = "myazurefileshare";
var share = fileClient.GetShareReference(baseShareName);
var rootDir = share.GetRootDirectoryReference();
var sampleDir = rootDir.GetDirectoryReference("MyFolder");
var fileToCreate = sampleDir.GetFileReference("output.txt");
fileToCreate.UploadText(".....");
有关Azure File Share(.Net)的更多信息,请参考此教程:https://docs.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files