Search code examples
azureazure-web-app-serviceazure-webjobsazure-webapps

How to download file and save to Azure WebApp's hard disk by WebJob


I have a web app with api what will read search engine's indexing files and return search result. Those indexing files will be updated to Blob Storage every day.

I want to make a web job. This web job will download all indexing files and save to web app hard disk.

I have reseached Microsoft's document, but cannot find anything. Can I make this by Azure Web Job?


Solution

  • You can use a background scheduled webjob or a queue triggered webjob to download the indexing files and store it in kudu with simple File IO operations and use a blob storage in storage account to upload the files created in kudu.

    It can be easily done in webjob using Azure.Storage.Blobs library.

    For Kudu simply use below to create a file in base directory in your Functions class.

    var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "myIndexedFilePathFolder", fileName);
    FileInfo fileInfo = new FileInfo(filePath);
    fileInfo.Directory.Create();
    File.WriteAllText(filePath, fileContent, Encoding.UTF8);
    

    Reference to Microsoft Learn article.

    So to answer your question in summary I think it is possible based on the limited information available in your question.

    Since we don't have much background context or information the best approach I think for you is to setup a sample project and see if this fits your requirements.