Azure function not able to write files to its fileshare

antonios peris 21 Reputation points
2022-03-09T10:42:54.093+00:00

Hey

So I'm deploying using Visual Studio Code.
Other colleagues use Visual Studio but behavior of deployment is similar.

The function then tries to create and save information into a file. But I always run into exceptions. Not listing them here but to my understanding, it seems that the Function doesn't have read/write access to the local fileshare that is created during initial deploy of the application.

For the file and directory path I have used code like this:

string startPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

this:
string startPath = System.IO.Path.GetTempPath(); -> points to /local/temp directory that doesnt really exists when looking into the FileShare using the Azure Portal

this:
string startPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); -> points to it's "bin" directory

even hardcoding like this:
string startPath = "C:\site\wwwroot\result"; or string startPath = "C:\home\site\wwwroot\result";

I do get different error messages, but in the end it never allows the Function to save into its local fileshare directory under "wwwroot", which is what I think it can read/write to.

Any ideas on how to enable the Function to be able to save/create files? What is the best practice when trying to use the file directory access and the correct "paths" to use?

Is it any deployment setting I need to be aware of?
Have tried playing around with the WEBSITE_RUN_FROM_PACKAGE setting, but not sure I should modify that.

Many thanks for your feedback.
Best Regards
/Antonios

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
0 comments No comments
{count} votes

Answer accepted by question author
  1. MughundhanRaveendran-MSFT 12,511 Reputation points
    2022-03-09T13:14:00.17+00:00

    @antonios peris ,

    Thanks for reaching out to Q&A.

    Every Azure Web App has a home directory stored/backed by Azure Storage. This network share is where applications store their content. This directory is available for the sandbox with read/write access. The file directory is either D:\ or C:\ , you can check this by opening the Kudu site of the function app (site is not available for Linux consumption app)

    Functions Sandbox restrictions : https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#file-system-restrictionsconsiderations

    181464-image.png

    You should be able to write the files to the site folder directory (in my case D:\Home\Site\wwwroot) however its not recommended to write files in this directory. I would strongly recommend you to write the files to a storage account either using Storage SDK or functions storage output binding

    I hope this helps!

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.