I'm trying to save a file to the local file system within an Azure Function. When I create the Function manually, I can access the d:homesitewwwroot directory and upload files both through the console and via code (like PowerShell). However, when I deploy the Function using VSCode or a CI pipeline, I encounter issues because the local file system appears to be read-only. Is there any workaround for this problem?
4 Answers
Most serverless platforms restrict the file system to read-only. However, they usually provide a temporary path you can use. Try changing your destination from d:homesitewwwroot to %TEMP%. You can find this by searching in Windows or using the Windows+R shortcut to run it.
Typically, the local file system in Azure Functions is read-only. But there's a workaround: you can use the GetTempPath method to save your file in the temporary directory instead. This should let you upload files without issues!
Just a heads-up, but using local storage isn't how cloud functions are intended to work. These functions are stateless by design, so you might want to consider using Blob Storage instead!
Exactly! Function apps are meant to be stateless, so sticking with Blob Storage is definitely the way to go.
It sounds like a permission issue to me. When you upload manually, does your account have contributor access, but not when going through the pipeline? That could be why you're facing issues! Also, what kind of files are you trying to upload?
That's what we've been doing to transfer files between storage accounts, and it's been working fine for us!