How can I upload a temporary file to my Azure Function?
Asked by
CuriousCat2023
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?
Answers
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?
Reply to this answer
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!
Reply to this answer
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!
DeveloperDude88: That's what we've been doing to transfer files between storage accounts, and it's been working fine for us!
Reply to this answer
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.
Reply to this answer
Add your answer
Answers are reviewed before publication.
StorageNinja22: Exactly! Function apps are meant to be stateless, so sticking with Blob Storage is definitely the way to go.