Azure Functions 临时存储 [英] Azure Functions Temp storage
问题描述
当我尝试将文件保存到 Azure Functions 目录 (D:homedata emp
esponse.pdf
) 中的临时存储时,我收到以下错误.为什么我不能写入这个目录?
When I try to save a file to the Temp storage in Azure Functions directory (D:homedata emp
esponse.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:homedata emp
esponse.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).
推荐答案
我建议使用 System.IO.Path.GetTempPath()
,因为这将始终为我们提供任何给定系统的有效路径.
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());
或者,我们可以使用 System.IO.Path.GetTempFileName()
在返回完整路径和唯一文件名之前额外创建文件.
Alternately, we can use System.IO.Path.GetTempFileName()
which will additionally create the file before returning the full path and unique filename.
这篇关于Azure Functions 临时存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!