If you have ever needed to send or store multiple files in a single operation, you might have wished for a way to compress them into a zip file. Zip files are convenient because they reduce the size and number of files, making them easier to transfer and manage. However, creating zip files programmatically can be challenging, especially if you want to do it in the cloud.
In this blog post, I will show you how to create an Azure Function that can accept base64 file content for an array of files and output a compressed file. This function can be useful for scenarios where you need to compress files from different sources and store or send them to different destinations, such as SFTP, Blob or email.
Table of Contents
- Set up an Azure Function from the portal
- Sample C# code for the function
- Test the function from the Azure portal
- Use the function from Power Automate or Logic Apps
- Conclusion
Set up an Azure Function from the portal
To create an Azure Function from the portal, you need to follow these steps:
- Log in to the Azure portal and click on Create a resource.
- Search for Function App and select it from the results.
- Click on Create and fill in the basic information, such as the subscription, resource group, function app name, runtime stack (choose .NET), region and hosting plan (choose Consumption).
- Click on Review + create and then on Create to deploy the function app.
- Once the deployment is complete, go to the resource and click on Functions in the left menu.
- Click on Create and choose HTTP trigger as the template.
- Give a name to the function (such as ZipFiles).
- Click on Create Function and wait for it to be created.
Sample C# code for the function
To setup the code for the Azure Function, you need to follow these steps:
- Go to the function you created and click on Code + Test in the left menu.
- Replace the default code with the following code.
- Click on Save
#r "Newtonsoft.Json" #r "System.IO.Compression" using System.Collections.Generic; using System.IO; using System.IO.Compression; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; public static async Task<IActionResult> Run(HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); if (string.IsNullOrEmpty(requestBody)) { return new BadRequestObjectResult("Invalid input. The request body is null or empty."); } try { // Deserialize the JSON request body into an array of file objects var files = JsonConvert.DeserializeObject<List<FileRequest>>(requestBody); using (var memoryStream = new MemoryStream()) { using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { foreach (var file in files) { var entry = archive.CreateEntry(file.FileName); using (var entryStream = entry.Open()) { // Convert base64 string to byte[] byte[] fileBytes = Convert.FromBase64String(file.FileContent); // Write the content of the file to the entry stream await entryStream.WriteAsync(fileBytes, 0, fileBytes.Length); } } } // Set the response headers var headers = new Dictionary<string, string> { { "Content-Disposition", "attachment; filename=files.zip" }, { "Content-Type", "application/zip" } }; return new FileContentResult(memoryStream.ToArray(), "application/zip") { FileDownloadName = "files.zip" }; } } catch (Exception ex) { log.LogError($"An error occurred: {ex.Message}"); return new StatusCodeResult(500); // Internal Server Error } } public class FileRequest { public string FileName { get; set; } public string FileContent { get; set; } // This is a base64 string }
Note that this code is provided without warranty and is therefore a proof of concept
Test the function from the Azure portal
To test the function from the Azure portal, you need to follow these steps:
- Navigate to the function app that you created and select the function that you want to test.
- Click on the Test/Run tab from the top navigation bar.
- In the Input box, enter the below sample JSON object that matches the schema of the function.
- Click on the Run button at the bottom of the screen. You should see the output of your function in the Output box below. You can also check the logs for any errors or messages from your function.
- A sample compressed base64 file output and a 200 OK status should be provided as the output to your function.
[ { "FileName": "textfile.txt", "FileContent": "SGVsbG8sIHdvcmxkIQ==" }, { "FileName": "image.png", "FileContent": "iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAY+0lEQVR42u1dCXhUVZYOrW339LQ9n35uQ2MMoVJvrUAIkKr3qiqVvRJRFkV22UGUTXawEVni2jraLq0ztOO0tk5r2y5tj9iOiuIyitq2+9YKIqgo2IoQFvHO+d9SdauSAGpeLcm933e/qlQqleSec8/5z3/OPbegQIzDGrIvVKkpxkZNi7zv9w/oLVakCw1Jqhij6+Eduh5lgUAlUxXzYXr5CLEyXWAoSmgO7fq9gUCU6XqEQQlUxdhSVBT7sVidzm72ZWMeCf1rCN0VPj0ekOXQYvp2N7FCnXhoijmZhL3fFnyEwQKQJWjxy6EZYnU6u9kvqagjYe90d75t/o1dilIxQqxOpzf7fYo0PfJe0udHmKZE9wAIitXp9CN2pKwa9wHpu8Kn+Y0mzH7XGKoanaZzOx+KoKnmtWJlusDoXlxeSH5/K+/3NdV41ufz/UysThcYumreyJt+TY18pSh9g2JlusDwqf3KSOhf8aZfUoxLxcp0Gd9v3J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+0bSDbuH6kJQIFzM/O6vBsjK4kGECJWsASgHo4NtL2tjt9jHt8AFdMdaRqR9Nfv6nQoIdNHr00I5VpYoxtMAP0v24O9OtgmsZXFPsTrwOweEI+zgiYXDDFi5ZWkKnbC4ksAbAtripis0hpZlCtDSuYBtIShQqs3e2zxE4Hvkwjkf0zimdLVQDsYYEXxXrajF95nFCRSn1w1lMuYWnVDWy0xVCukK4SgHBSc6uda1FsdJ6+pz3yGpbwk4VuH1Pb2SrokTu1bTgOK24vFBIJvPjiEBxKEC3mk4hUuUuSqS8RruwhRdSe4px8Nn6523ixthONPYGXNDsVyKD6Q6FU4QIcotd/BkuuaZdOULVzYsp5r6f8uobSKjv0fwcvfTbEmyqkhi76aTTNrqE+U3a4U+peuQ2RTMW+pWKJrk47C8Q5j3fRuxI5B78/pCsU4USuY8q0K/UVGEUbteiNPUEaoA5HALWpIhZUmL0AUNXWBg4piut0v8D1HLTMIZOOhsAAAAASUVORK5CYII=" } ]
Use the function from Power Automate or Logic Apps
To use the function from Power Automate, follow these steps:
- Obtain the base64 file output for each file you want to add to the zip. You can do this by using the Get file content using path action from the SharePoint connector, or by using other connectors or APIs that provide the same functionality.
- Create an array variable and append an object with the file name and content for each file, as shown in the sample JSON array above.
- Send an HTTP post request to the function rest api with the array variable as the body. You can do this by using the HTTP action from the built-in connectors.
- Save the body output of the HTTP response to your desired destination. You can do this by using the Create file action from the SFTP connector, the Create blob action from the Azure Blob Storage connector, or the Send an email (V2) action from the Office 365 Outlook connector to send the output as an attachment.
Below is a sample flow screenshot
- We use the OneDrive Connector Action “List files in folder” to obtain a number of files.
- Then, we “get file content” and create an object with the file name and base64 content in a compose action. This way, we do not need to initialise an array variable and append the object to it.
- The image below shows the JSON object structure and the expression to get the base64 content encoding into the Compose action called ComposeFile.
- Then from the Code + Test pane of the Azure Function, we obtain the Azure Function URL via the Get function URL button on the navigation bar. Copy this to your clipboard.
- Add an HTTP actions and paste in the URL
- Set the Method to POST
- Set the Body to the expression outputs(‘ComposeFile’) which will be an array of the objects created in the apply to each (note that if you are more confident with using a variable and append to array variable you can do this instead).
- Finally add a create file action, in the above example I have used the OneDrive connector create file action, where the File Content is set to the Body of the HTTP action.
Conclusion
In this blog post, you learned how to create an Azure Function that can zip files from base64 content. This function can be useful for scenarios where you need to compress files from different sources and store or send them to different destinations. You also learned how to test the function from the Azure portal and how to use it from Power Automate or Logic Apps. I hope you found this post helpful and that you will try out this function in your own projects. If you have any questions or feedback, please leave a comment below.
Very Nice tutorial. Do you think it is possible to update the code so it can Zip, encrypt and setup a password on the file?
I’ve not tried it myself but would guess that with pro code this is possible 👍 let me know how you get on.
Hi
I’m trying to do something similar but instead of using the azure function, I am trying to convert xlsx files to xlsb. I am struggling to figure out what to return from azure function after passing the base65 encoding.
If my azure function returns the xlsb in base65, would I be able create the file on Sharepoint?
any help is appreciated.
You could use create file. A nice use of an azure function 👍
FYI: Your code creates a variable called headers, but never uses it.
Thanks for the spot 👍
Hello,
I’m trying to create the same thing but with SharePoint. Are there any limits regarding the file size and the number of files that the folder can contain?