0
votes

I have created two storage accounts, one have my azure function while another is a file storage account. What I want is to create a file from azure function and store it in my azure file storage. I went through official documentation of file storage as well as of Azure function, but I am not finding any connecting link between the two.

Is it possible to create file from azure function and store it in file storage account, if yes, please assist accordingly.

1
You can use Azure Storage SDK to store data in a file storage account.Gaurav Mantri
Thanks..but can you elaborate as exactly how to do that..The documentation is little confusingKaran Desai
I think it would be hard for me to explain the basic concepts of uploading file. If you read the documentation, you will find plenty examples about uploading a file in a file service share. Please follow those examples. Once you have done that and still have some questions, please update your questions with the code you have written and the problems you are running into.Gaurav Mantri
If I am not mistaken, it is not supported as of today. Blob output binding is supported though.Gaurav Mantri
We don't have a first class Azure Files binding. This is tracked as a feature in our repo here: github.com/Azure/azure-webjobs-sdk-extensions/issues/14mathewc

1 Answers

3
votes

There is a preview of Azure Functions External File bindings to upload file to external storage, but it doesn't work with Azure File Storage. There is a github issue to create a new type of binding for Files.

Meanwhile, you can upload the file just by using Azure Storage SDK directly. Something like

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

public static void Run(string input)
{
    var storageAccount = CloudStorageAccount.Parse("...");
    var fileClient = storageAccount.CreateCloudFileClient();
    var share = fileClient.GetShareReference("...");
    var rootDir = share.GetRootDirectoryReference();  
    var sampleDir = rootDir.GetDirectoryReference("MyFolder");
    var fileToCreate = sampleDir.GetFileReference("output.txt");
    fileToCreate.UploadText("Hello " + input);
}