Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions Temp storage

When I try to save a file to the Temp storage in Azure Functions directory (D:\home\data\temp\response.pdf), I get the following error. Why can't I write to this directory?

mscorlib: Exception has been thrown by the target of an invocation. System: An exception occurred during a WebClient request. mscorlib: ***Could not find a part of the path 'D:\home\data\temp\response.pdf'.*** 2017-09-19T07:05:24.353 Function completed (Failure, Id=3aa4b740-ba8a-465c-ad7c-75b38fa2a472, Duration=334ms) 2017-09-19T07:06:31  No new trace in the past 1 min(s). 
like image 906
naag Avatar asked Sep 19 '17 07:09

naag


People also ask

Does Azure function need storage account?

Storage account requirementsWhen creating a function app, you must create or link to a general-purpose Azure Storage account that supports Blob, Queue, and Table storage. This requirement exists because Functions relies on Azure Storage for operations such as managing triggers and logging function executions.

Where are Azure function files stored?

Folder structure. The code for all the functions in a specific function app is located in a root project folder that contains a host configuration file. The host. json file contains runtime-specific configurations and is in the root folder of the function app.

How long can Azure functions run?

How Long Can Azure Functions Run? For any Azure Functions, a single Function execution has a maximum of 5 minutes by default to execute. If the Function is running longer than the maximum timeout, then the Azure Functions runtime can end the process at any point after the maximum timeout has been reached.


2 Answers

I recommend using System.IO.Path.GetTempPath() as this will always give us a valid path for any given system.

Additionally, functions may execute multiple times simultaneously for a given instance, so it's best to ensure we have a unique path for each execution. Here's a simple example:

var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); 

Alternately, we can use System.IO.Path.GetTempFileName() which will additionally create the file before returning the full path and unique filename.

like image 101
defines Avatar answered Sep 20 '22 13:09

defines


I find a better choice. You can use System.IO.Path.GetTempFileName() this create a %userprofile%\Local\Temp\tmpE128.tmp file

like image 24
Ivan Rosales Avatar answered Sep 22 '22 13:09

Ivan Rosales