Azure-functions-host: Should have the capability to store the file locally during the execution of the function. #feature-request

Created on 3 Aug 2016  路  1Comment  路  Source: Azure/azure-functions-host

Let's say i have to download an image from an URL and then attach it to let's say a mail to send. Now, till it gets attached in the mail, i need to save it at some path after that i can afford to lose the image since i just need till the the function execution.

Most helpful comment

You have access to the local file system in Functions. For example, the below function writes/reads a temp file. You can do the same thing in the other languages. Is this what you're looking for?

using System;
using System.IO;

public static void Run(string input, TraceWriter log)
{
    log.Info($"C# manually triggered function called with input: {input}");

    string tempDir = Path.Combine(Path.GetTempPath(), "MyData");
    if (!Directory.Exists(tempDir))
    {
        Directory.CreateDirectory(tempDir);
    }
    string tempFile = Path.Combine(tempDir, "test.txt");
    File.WriteAllText(tempFile, "Test");
    string result = File.ReadAllText(tempFile);

    log.Info(result);
}

>All comments

You have access to the local file system in Functions. For example, the below function writes/reads a temp file. You can do the same thing in the other languages. Is this what you're looking for?

using System;
using System.IO;

public static void Run(string input, TraceWriter log)
{
    log.Info($"C# manually triggered function called with input: {input}");

    string tempDir = Path.Combine(Path.GetTempPath(), "MyData");
    if (!Directory.Exists(tempDir))
    {
        Directory.CreateDirectory(tempDir);
    }
    string tempFile = Path.Combine(tempDir, "test.txt");
    File.WriteAllText(tempFile, "Test");
    string result = File.ReadAllText(tempFile);

    log.Info(result);
}
Was this page helpful?
0 / 5 - 0 ratings