尝试在WebJob中使用TempPath时出错

时间:2018-12-03 21:16:44

标签: c# azure azure-webjobs

我正在尝试将文件下载到Azure WebJob的temp文件夹中...

 public static string DownloadLogo(string url)
    {
        var fileName = $"{Path.GetTempPath()}logo.png";

        using (var client = new WebClient())
        {
            client.DownloadFile(url, fileName);
        }
        return fileName;
    }

我遇到以下错误:

Exception: System.Net.WebException: Could not find a part of the path 'D:\local\Temp\jobs\continuous\BillingProcessor\t2argeef.l1b\public\logo.png'. ---> System.Net.WebException: Could not find a part of the path 'D:\local\Temp\jobs\continuous\BillingProcessor\t2argeef.l1b\public\logo.png'. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\local\Temp\jobs\continuous\BillingProcessor\t2argeef.l1b\public\logo.png'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async)
   at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
   --- End of inner exception stack trace ---
   at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
   at System.Net.FileWebRequest.GetResponseCallback(Object state)
   --- End of inner exception stack trace ---
   at System.Net.WebClient.DownloadFile(Uri address, String fileName)

单独注释:

  1. 我导航到D:\ local \ Temp \ jobs \ continuous \ BillingProcessor \ t2argeef.l1b \,但公用文件夹不存在
  2. 我有相同的代码运行其他webjob部署而没有任何问题

1 个答案:

答案 0 :(得分:0)

我尝试了您的代码,但效果很好。但是我的文件名是D:\local\Temp\logo.png,与您的文件名不同。

因此,我尝试将路径更改为{Path.GetTempPath()}t2argeef.l1b/public/logo.png,然后它将显示与您相同的错误。因此,现在我可以确定问题是文件夹不存在。

我解决问题的方法是转到 Kudu 并创建如pic所示的文件夹。然后运行 webjob ,一切正常。这就是result

我认为您的 kudu 环境TEMP已更改,这导致您的临时文件夹目录错误。因此,您可以使用TEMPKudu console或Kudu环境page检查set环境。

如果您仍有疑问,请告诉我。

相关问题