Skip to main content

Uploading a file from a SharePoint document library into an Azure Blob Storage with Microsoft Flow (or Logic App)


The Problem

One of the things that I've been experimenting with lately is Microsoft Flow. The service allows you to build process automation to facilitate transfer of information from one system to another easily.

One scenario I wanted to try out is to be able to copy/move a file from SharePoint to an Azure Blob Storage. There are a number of reasons that you may want to do this:

  • Archive files that are no longer needed
  • Upload a copy of a file (usually an image) into a Blob Storage so that images can be hosted in a CDN to optimize page load performance
In the past doing something like this would have required some form of custom development e.g. a remote event receiver. However the introduction of Microsoft Flow and Logic Apps has created another alternative that is worth exploring....

Update 30/09/16: If you are looking to put your assets into a CDN to make it load faster, then it's worth checking out the new Preview Release Office 365 Public Content Delivery Network (CDN) capability in the Office 365. However this will only work if the files are used within SharePoint, and according to the content cannot be used externally

Difference between Microsoft Flow and Logic Apps

Microsoft Flow is a service that is built on top of the Logic Apps platform and as such the functionalities offered in Microsoft Flow is similar to Logic Apps. The difference between both in my own opinion are:
  • Microsoft Flow: is a user friendly version of Logic Apps that makes it easy for business users to create solutions that automate information transfer between different systems. If you have used IFTTT (If This Then That), then Flow seems to be a business version of that service.
  • Logic Apps: is a pro version of Microsoft Flow that provides developers more functionality for developers (e.g. allows developers to build and deploy their solution in Visual Studio in addition to the graphic browser based designer) as well as more controls for IT (more advanced monitoring tools)

The Solution

High Level Steps

The high level steps involved in creating this solution are:
  1. Create an Azure Blob Storage Account
  2. Add a container (otherwise known as folder) inside your Azure Blob Storage Account
  3. Create your Microsoft Flow or Logic App Solution
Disclaimer: It is worth noting that Microsoft Flow is still in preview. In addition, though initial testing looks promising it is recommended that you perform load testing on such a solution to ensure it is robust enough for your needs. 

1. Create an Azure Blob Account

  1. Go to the Azure Portal
  2. Click on the New Button, and search for "Storage Account"
  3. Click on the Storage Account and confirm that you want to create one
  4. Fill out the form and choose the option that applies best to your circumstance and click Submit
    (Tip: whilst tempting to choose "premium options" consider whether they are required for your circumstance e.g. if you are just testing the scenario, then it's probably good enough to use the standard performance, locally redundant storage etc.)
  5. Your storage account should start provisioning and will be ready in a short while

2. Add a container inside your blob storage account

The container acts as a "folder" which will hold the files that you send over from the SharePoint Document Library

  1. Once the storage account has been created, open it (it can be found in the All Resources page)
  2. In the overview section, click on the add container button
  3. Fill out the form as appropriate to your circumstance and click Create
  4. This folder is where you will see your files once you get your solution working

3. Create your Microsoft App or Logic App solution

For the purpose of this blog post, the screenshot will be taken from Microsoft Flow. However the configuration between both products are similar (if not the same).

  1. Go to flow.microsoft.com and sign in using your Office 365 account
  2. Click on My Flows > Create from blank
  3. Add the action: SharePoint - When a file is created
  4. Sign in using your Office 365 account (if you have previously not done so)
  5. Paste the URL of the site where the document library you want to use lives (you may also be asked to sign in with your office 365 account if you have not previously done so)
  6. Click the folder icon to select the document library you would like to monitor for new uploaded files
  7. Add the action: AzureBlobStorage - Create file
  8. Configure your connection in the AzureBlobStorage and submit your changes

    Connection Name: Copy this value from the property called "Primary blob service endpoint" (accessed in the Azure Portal by going to Storage Account > Overview)

    Azure Storage Account Name: Copy this value from the property called "Storage account name" (accessed in the Azure Portal by going to Storage Account > Access keys)

    Azure Storage Account Access Key: Copy this value from the property called "key 1" (accessed in the Azure Portal by going to Storage Account > Access keys)

  9. Click the folder icon to select the container that you created earlier in this blog post
  10. Fill out the remaining fields in the form:

    File name: Choose File name from the outputs returned from the SharePoint action
    File content: Choose File content from the outputs returned from the SharePoint action

  11. Add the action: Mail - Send Email (this step and the remaining steps in this section is optional)

    This will help us with our testing by getting the flow to email us the link to the file in Azure blob storage.
  12. Accept the terms and conditions (if you have not previously done so)
  13. Fill out the fields in the form:

    To: Enter your email
    Subject: Enter any value
    Body: Copy and paste the URL from the property "Primary blob service endpoint", and then choose the Path from the outputs returned from the create file in Azure Blob Storage action
  14. Save your flow

Testing the flow

Your flow should now be ready to test, so let's upload a file and wait for the email to come to us with a link to the file stored in the Azure Blob Storage.

It's also worth noting that Microsoft Flow (and Logic Apps) provides us with the ability to monitor the flow to see if any runs have failed. 

List of successful and failed runs in the flow solution we created

Detailed level for each individual run that shows things like that passed through the actions

Next Steps

  • Have you used Microsoft Flow or Logic Apps to move or copy a file from SharePoint to Azure Blob Storage? Share your experience in the comments below
  • Check out the documentation in the flow website for some useful getting started content

Popular posts from this blog

Access Web App | Filter a view by current user login (deprecated)

Update (April 1 2017): Microsoft has released an update that willl stop the creation of new apps starting June 2017, and shut down any remaining apps by April 2018. See more here

The problem One of the things I needed to do lately was see if a view within Access Web Apps can be configured to filter data that is related to the logged in user. e.g. as a user I want to be able to view a list of projects where I had been assigned as the project owner.

In SharePoint, this would have been quite easy to achieve as we can create a view and set the filter to {column name} is equal to [me].

Unfortunately Access Web Apps does not quite work this way:

No people picker control in Access Web Apps - this means we need to store and manage our own list of user data within a table in your Access Web App Database (or find a way to link a table with SharePoint's user profile or hidden user information list).Access Web Apps is a relational database - this means the approach to filtering a table view is…

Nintex Workflow | parsing JSON responses from json-only web requests

Update 03/08/16:
Logic Apps has gone GA, and has undergone a major v2 change since this post was written. For the most part, the core actions remain the same but just renamed or work a little differently e.g. http listener (now known as "When an http request is received" + "Received") and conditions (now triggered via the add a condition" button instead of being configured inside the http action.)

It is worth noting that the BizTalk JSON Encoder API app can no longer be found in the marketplace. This is now a native function in Logic Apps. Though, I'll try to refresh this post with the how to do it in the version of Logic Apps that GA'd, I'm not sure when I will have to do it, so if you can't wait, I suggest looking at the xml function can be found here.

Update 07/08/16:
Steps for new Logic App UI that has GA have been added into the solution section below.
The problem
One of the things I have been working on lately in the Nintex Workflow world,…

An intro to conditional validation and formatting in PowerApps (using SharePoint as a data source)

The Problem What if we need to create a form that changes it's behaviour based on the answer entered by the user.

For example, we need to build a leave request form that: Shows the comment field if applying for a sick leave, but hides the comment field if applying for a annual leaveRequires the requestor to write a comment if their sick leave is more than 1 day, but is optional if sick for just 1 day.  The default form interface for custom lists in SharePoint Online can be used for basic scenarios, but doesn't provide an easy way to add business logic described above (unless you want to write some javascript)

In the past InfoPath would have been the tool of choice for many, however this tool is now in maintenance mode and whilst it will still be supported for a wee while there will be no improvements or enhancements to the platform.

The Solution This is where PowerApps come in. PowerApps is now the platform that is recommended by Microsoft as a way for business users to create…