1

I have an Azure Function v2 with c#.net core code running on dedicated App Service Plan. The function downloads files and then uploads them via Microsoft Graph to a Sharepoint Library.

My code looks like this
 var path = System.IO.Path.GetTempPath() + downloadedfileName;
 using (var stream = System.IO.File.Create(path)                
 {
    //put content from downloaded file into stream
    //call graph to use the stream and upload the content.
 }

This code works fine, but I am concerned about running out of temp space. The question I have is:

  1. When will this temp file get cleared
  2. If it is not cleared automatically then how do i clear it?
  3. Is there any other alternative way to handle this upload scenario?
Azure Dev
  • 61
  • 2
  • 9
  • if you want to make sure, why don't you just delete the file at the end of your code flow? – silent Mar 13 '20 at 16:01
  • Thank you for the response. I would like to know how these temp files are being handled by Azure Function App. If they are not getting cleared at all, then i will have to do as you suggested. – Azure Dev Mar 13 '20 at 16:43
  • Since you are running in App Service Mode: this should be your answer (applies in the same way for Functons then) https://stackoverflow.com/questions/34247801/azure-web-app-temp-file-cleaning-responsibility – silent Mar 13 '20 at 16:45
  • @AzureDev31 Yes, temporary files are not automatically cleared at all. You need to restart the startup site manually. Have a look of this doc: https://github.com/projectkudu/kudu/wiki/Understanding-the-Azure-App-Service-file-system#temporary-files – Cindy Pau Mar 16 '20 at 02:04

1 Answers1

1

Please have a look of this doc.

There is no automatic method, you can only do it manually. Since Azure Function is a Web App sandbox, if you don't delete files in your code, the method you can choose is the restart site provided in the doc.

enter image description here enter image description here

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • Thanks @BowmanZhu. It would have been great if Azure function can handle clean up of unused files automatically instead of we doing it manually via restarts. In my code now i have added the option to delete the file using using (var stream = File.Create(filename, buffersize, FileOptions.DeleteOnClose)). Do you think i can see this temp files in the D:/home directory? – Azure Dev Mar 17 '20 at 19:53
  • @AzureDev31 No, it is not in the `D:/home`. It should be `D:\local\Temp>` and `D:\local\AppData>`. Use kudu tools go to that and then you can have a look.:) – Cindy Pau Mar 18 '20 at 09:24