Azure Logic App
The azure logic app is a deject-based service provided by Microsoft to help you lot create serverless workflows without writing a single piece of code. It's a designer showtime integration workflow engine, which provides an innovative designer to quickly create your integrations. Information technology has more 200 built-in connectors to allow you to connect to different on-premises and cloud-based data sources/systems/services. It supports simple data, B2B, application and enterprise-level integrations.
Trouble
Azure logic apps provide a great variety of deportment to work with the Azure file shares similar creating, copying, deleting, updating files etc, on the Azure file share. Another great born action it provides is to extract the content of the archived file that is on the Azure file share to a item folder on the Azure file share and it works great until the file size is under the 50MB limit. You get an error as shown below when file sizes are larger than 50MB.
Solution
To resolve this trouble, we volition make utilise of the Azure function to read the file from the Azure File share and excerpt it to the desired location on the Azure File share. This will help us become away with the 50MB limit on the file size. In addition, you can't directly extract the file to the Azure file share, so for that, you get-go need to download the archive, excerpt it locally and so upload it to the desired destination. And if y'all would like to exercise any other manipulation with the extracted files you can do that as well.
Create a new Azure Function projection in Visual Studio
We'll create a new Azure function project as shown below
We'll utilise the HTTP trigger, as we will pass the annal file name that resides on the Azure file share to be extracted.
Install Azure Storage File Shares client library from the Nuget
Open Nuget Parcel manager by right-clicking on the Solution and search for "Azure.Storage.Files.Shares" and install it.
Connect to the File share to excerpt the archive file
Nosotros will include the following namespaces in our Azure part form.
Azure.Storage.Files.Shares; // For accessing ShareFile Client objects Azure.Storage.Files.Shares.Models; // For download info object to download the file System; // to access surroundings variables System.IO; // to access file stream System.IO.Pinch; // For enabling united states to extract the annal Organization.Cyberspace; // for http status code enum
Get Connection String for Azure File Share
To be able to connect to the Azure File share to access the file you need the connection string.
- Go to your Azure portal, select the storage account that has your file shares.
- Select "Admission Keys" from the left side pane.
- Click the "Show Keys" push and copy the connection string
Keep the connection string in the local.settings.json file as information technology should not be hardcoded in the class file.
Now nosotros volition create the connection to the fileshare, access the particular file with the proper noun as what is provided in the querystring to the Azure role. Nosotros will extract the file to the temp directory every bit that is the just directory that we volition have access to when our role is deployed on Azure. The beneath is the final code of the function.
public static class Function1 { [FunctionName("Function1")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "go", "mail service", Route = aught)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string connectionString = Environment.GetEnvironmentVariable("AzureFileShareConnectionString"); // the local path where the archive file will exist extracted to var unzipPath = Path.Combine(Path.GetTempPath(), "unzip"); try { // create the local folder for extracted files Directory.CreateDirectory(unzipPath); // Name of the share, directory, and file nosotros'll download from string shareName = "myshare"; // name of the file share string dirName = "folder1"; // name of the folder where the archive file resides string fileName = req.Query["fileName"]; // name of the file to be looked for in fileshare cord extractedFilesDirName = "ExtractedFiles"; //name of the folder on the file share to upload extracted files to // Go a reference to the ShareClient share = new ShareClient(connectionString, shareName); ShareDirectoryClient directory = share.GetDirectoryClient(dirName); // directory where the archive resides ShareDirectoryClient directoryForExtractedFiles = share.GetDirectoryClient(extractedFilesDirName); // directory where extracted files will be uploaded ShareFileClient file = directory.GetFileClient(fileName); // Download the file ShareFileDownloadInfo download = file.Download(); ZipArchive zipArchive = new ZipArchive(download.Content); zipArchive.ExtractToDirectory(unzipPath, true); foreach (var fname in Directory.GetFiles(unzipPath)) { using (FileStream fs = File.OpenRead(fname)) { ShareFileClient fileToUpload = directoryForExtractedFiles.GetFileClient(Path.GetFileName(fname)); wait fileToUpload.CreateAsync(fs.Length); await fileToUpload.UploadAsync(fs); } } render new OkResult(); } catch (Exception ex) { log.LogError(ex, "error occurred!"); return new StatusCodeResult((int)HttpStatusCode.InternalServerError); } finally { if (Directory.Exists(unzipPath)) Directory.Delete(unzipPath, true); } } }
Note: Y'all tin modify the code to take the folder where the archive file resides and also the binder where you lot need to excerpt as an input to the function app using querystring or mail torso.
Publish the function to Azure using VS2019
Right-click on the project in the solution explorer and select publish.
Side by side, click on the "Showtime" every bit shown beneath
Then select Azure from the dialog that appears, every bit shown below
Side by side, Select "Azure Function App (Windows)", or whichever service you like to host.
Next, sign in to your Azure account. Then change the "View" dropdown to "Resource type" and select the appropriate role app. Or you could also create a new one by selecting the "Create a new Azure Function" link.
Click Finish and the beneath screen will prove upward. Next, click on the "Publish" push and it will start deploying your function to Azure.
Setup the connexion cord value in the environs variable in Azure
One time the office app is deployed, you need to do one more thing: set the connection cord value for the Azure file share. To do that, go to your function app in Azure. Select Configuration under Settings from the side pane.
Select New application setting. Enter the name "AzureFileShareConnectionString" equally nosotros did in the localsettings file and for the value, paste the connexion string for the Azure File Share gathered previously.
Press OK.
Using the Azure Office in your Logic App
- Open up your logic app
- Click the plus icon to "Add an action"
- On the Choose an performance dialog, type "Azure Function" in the search box, and select "Choose an Azure function" under the Actions tab
- Then choose your office app. It will show y'all all the functions within information technology.
- Select your appropriate role
- Open the Add new parameter dropdown and select the post-obit
- Now select the method as "Get", and add your query parameters in the JSON form
Salvage the logic app and you are skilful to go. :)
DOWNLOAD HERE
Posted by: rossreery1967.blogspot.com
Post a Comment