PowerApps upload file to SharePoint document library

In this PowerApps tutorial, we will discuss how to upload a file or a document to SharePoint Online Document Library using PowerApps. Let us see, PowerApps upload file to SharePoint document library.

For this, we will also use the Microsoft Flow or Power Automate.

Also, We will see these below things as:

  • How we can upload and tag multiple files to SharePoint Document Library using PowerApps Attachment control
  • PowerApps upload files to SharePoint Library using Power Automate/Microsoft Flow
  • PowerApps upload files to SharePoint Document Library with a different type of SharePoint columns
  • PowerApps upload file to sharepoint document library
  • PowerApps upload attachment to sharepoint
  • Powerapps upload excel file to sharepoint
  • Powerapps upload multiple files to sharepoint
  • upload multiple files from PowerApps to sharepoint document library
  • Powerapps upload multiple files to sharepoint
  • Powerapps upload image to sharepoint
  • upload a file to sharepoint from PowerApps

PowerApps Upload File to SharePoint Library

Let us see first how to upload file to SharePoint document library in PowerApps.

In my SharePoint Online Site, I have a SharePoint Document Library named TSInfo Documents. This library has these below columns as:

  1. Name: By default, it is a single line of text column.
  2. Modified: It is a Date and Time Data type column.
  3. Modified By: Person or Group Data type column.
  4. Document Type: It is a Choice Data type column having some choice values.
  5. Department: It is also a Choice Data type column having some choice values.
powerapps upload file to sharepoint document library
powerapps upload file to sharepoint document library
  • Here in this scenario what I want to do is, When a user will press a Powerapps button, then it will upload a single file or multiple files (like excel file, ms documents, image file, pdf file, etc) to this SharePoint Document library (TSInfo Documents).
  • As I have seen many posts, most of the people are using the PowerApps Add picture control to upload the files in the SharePoint Document Library.
  • Normally, When you will add an Add picture control to the Powerapps screen, by default, it appears with a Button and image control that looks like below:
power apps upload files to sharepoint library
powerapps upload attachment to sharepoint
  • Once you will click or tap the control, then it will ask you to upload your desire files from your local system.
  • But here the problem is when you will upload any file, every time you need to change the File options to All Files, and then you can select any types of files (like image file, pdf file, excel file, etc.) from your system.
Upload Powerapps documents to SharePoint document library
powerapps upload excel file to sharepoint
  • It is such an irritating thing that every time you need to select the All Files option to upload different types of files in Powerapps. To avoid this type of problem and make it to as simple, I will use the PowerApps Attachment control.
  • In the case of PowerApps Attachment control, you do not need to change the File options, directly you can attach any files (image file, pdf file, ms documents, etc) from your local system and use it as like the below screenshot:
Upload files to SharePoint Library using PowerApps Attachment Control
powerapps upload multiple files to sharepoint

Upload multiple files to SharePoint Document Library using PowerApps Attachment Control

Now, let us see how to upload multiple files from powerapps to sharepoint document library.

As we discussed above, the easiest way to upload multiple files to SharePoint Document Library, We can use the PowerApps Attachment Control. But the main thing we need to know is how we can add an Attachment control in the Powerapps screen as there is no Powerapps inbuilt control that we can find out in the app.

To add an Attachment control on the PowerApps screen, We need to follow these below things:

  • Go to View tab -> Data sources -> Search SharePoint -> Add a new or existing connection -> Select the SharePoint site -> Choose any SharePoint list (you can take any SharePoint list) -> Click on Connect button. Then the specific SharePoint list has been added to the app.
  • Next, insert an Edit form (Insert -> Forms -> Edit). Select the edit form and go to the Properties pane (from the right side of the page). Select the Data source as your SharePoint List (Company Info).
  • Once you will add the SharePoint list data source, you can able to see an attachment control has been added to the edit form automatically as shown below.
upload files to SharePoint library using power apps attachment control
upload multiple files from powerapps to sharepoint document library
  • Just select the attachment control and unlock it. Now just copy the attachment data card (Select the data card -> right-click on it -> click on copy) and then paste (right-click -> Paste) it in the outside of the edit form.
upload multiple files in SharePoint library using powerapps attachment control
powerapps upload multiple files to sharepoint
  • Once you pasted the attachment control, you can remove the edit form from the app. As the form is not needed further so that we can remove it (we need only the attachment control).
  • Rename the Attachment control to AttachFiles as like below. You can see some error will appear in the Attachment control. Once you will click on the error symbol, then you can see what are those errors appear in some of the attached properties.
  • You can edit the error from the formula bar and just remove it and make all those blank.
PowerApps Upload Files to SharePoint Library
powerapps upload image to sharepoint
  • Now the attachment control is ready to attach any type of file. Save and Preview (F5) the app.
  • Click on Attach file link from the attachment control. It will ask you to attach the file from your local system. You can attach any file to the Attachment control.
  • The benefit is, you do not need to make the File option as All Files during each and every time of attaching the file.
Upload Files to SharePoint Library using PowerApps
upload a file to sharepoint from powerapps

Create PowerApps Attachment Collection

  • Now we will create a PowerApps collection that will help to store all the files at the time of attaching.
  • Select the Attachment control (Attach Files) and apply this below formula on its OnAddFile properties as:
OnAddFile = ClearCollect(attachCollection, AttachFiles.Attachments)

Where,

  1. ClearCollect = Collect is the Powerapps function that helps to create the Powerapps collection. The ClearCollect function will always clear the previous values and take the recent values
  2. attachCollection = Powerapps Collection name where the attach files will store
  3. AttachFiles = Powerapps Attachment control name
powerapps upload file to sharepoint library
powerapps upload file to sharepoint document library
  • Similarly, go to the OnRemoveFile properties and apply the same formula as in the above properties (OnAddFile).
powerapps upload a file to sharepoint library
powerapps upload attachment to sharepoint
  • Save and Preview the app. Attach some different types of files using the Attach file option.
  • Once you attached, then open the Powerapps Collections (View -> Collections -> attachCollection). Here, you can see the attached files will store with two different categories as:
  1. Name: It specifies the file name that I have uploaded.
  2. Value: It is not a Datastream. Its a URL to local blob storage in Powerapps where it is maintaining the reference to the file. As this is a link, so we can not pass this value to flow because flow cannot understand the link and it can not convert into Binary.

For that, We need to create a Data stream that should contain an image of the file. If we will create a Datastream, then the flow will understand and it will easily convert into Binary format to upload the file into SharePoint.

How to upload a file to SharePoint in Powerapps
powerapps upload excel file to sharepoint

To create a Data stream we need to add a Picture control where we can get the Data stream. Follow the below things that we needs to do:

  • Create a PowerApps Gallery control and add the collection Data source that you have created recently. (Select the gallery -> Go to Properties pane -> Select attachCollection from Data source)
  • Select the Title field of the gallery control and rename the Title to lblTitle. Similarly, select the Image field and rename it to imgDataStream.
  • Select the image field or control from the gallery. Image control should be ThisItem.value. Because the Value has the link to the local blob storage.
Powerapps upload files to SharePoint library using Attachment control
powerapps upload multiple files to sharepoint
  • As it is an image file, so I need to attach an image to the attachment control and then we can see the image in the gallery control.
Powerapps upload file to SharePoint library using Attachment control
upload multiple files from powerapps to sharepoint document library
  • Now we do not need the gallery control. So we can hide it from the Powerapps screen (select the Gallery -> Properties -> toggle off to Visible property).
  • Insert a Button (Insert -> Button) and set its Text property to Upload Files to SharePoint Library.
  • As we need to create the Datastream from the gallery control itself (because it is having the image control), that’s why we will create another collection in the PowerApps Button. So that instead of Value, we can get the Datastream from the collection.
  • Select the Button (Upload Files to SharePoint Library) and apply this below formula on its OnSelect property as:
OnSelect = Clear(colAttachmentGallery);
ForAll(
    Gallery1.AllItems,
    Collect(
        colAttachmentGallery,
        {
            Title: lblTitle.Text,
            DataStream: imgDataStream.Image
        }
    )
);

Where,

  1. colAttachmentGallery = PowerApps Collection Name
  2. Gallery1 = PowerApps Gallery control name
  3. lblTitle = Label control name that is present inside the gallery control
  4. imgDataStream = Image control name that is present inside the gallery control
PowerApps upload file to SharePoint
powerapps upload multiple files to sharepoint
  • Save and Preview the app. Attach some files (including image files) from your local system and then hit on the button (Upload Files to SharePoint Library).
  • Go to the PowerApps Collections and open the new collection (colAttachmentGallery). Now you can see there are two columns available named DataStream and Title as shown below.
PowerApps upload files to SharePoint
powerapps upload image to sharepoint

PowerApps Upload File to SharePoint Library using Flow

Now its time to create a Power automate or flow that will help you to upload a single file or multiple files to SharePoint Document Library. Follow these below steps to create a flow from PowerApps app and use in PowerApps.

Step-1:

  • On the PowerApps screen, select the PowerApps Button (Upload Files to SharePoint Library) -> Go to Action tab -> Power Automate -> + Create a new flow.
PowerApps Upload File to SharePoint Library using Flow
upload a file to sharepoint from powerapps

Step-2:

  • Go to My flows (from the left navigation) -> Click on +New tab (from top) -> Select + Instant–from blank -> Enter a name for the flow (Upload Files to SharePoint Library) -> Choose PowerApps to trigger the flow -> Hit on Create button.
Powerapps upload files to library using flow

Step-3:

  • Next, the new flow will open with the PowerApps action (because you have chosen PowerApps to trigger the flow). Add a new step and insert an Initialize variable action under the PowerApps action. Enter these below field values as:
  1. Name: Type a name for the variable (varUploadFiles).
  2. Type: Select the type as String from the dropdown.
  3. Value: Go to the Dynamic content tab and click on Ask in PowerApps option. Whenever I called this flow from Powerapps, this is the value that the flow will expect Powerapps to pass. It is expecting a String value that is coming from the PowerApps.
upload files to library using Powerapps
powerapps upload file to sharepoint document library

Step-4:

  • Insert a Compose action below the Initialize variable and enter the Inputs value as:
  1. Inputs: Go to the Expression tab and apply the formula as json(variables(‘varUploadFiles’)). Where varUploadFiles is the variable name (from the Initialize variable action). Here we are converting the Powerapps variable to JSON format.
Powerapps upload multiple files to SharePoint library using flow

Step-5:

  • Now just save the flow and go back to the PowerApps app. Add that flow to the PowerApps button (Upload Files to SharePoint Library). Select the button -> Go to Action tab -> Power Automate -> click on the flow name (Upload Files to SharePoint Library) -> flow will be added to the button.
  • Once the flow will add to the button, then it will appear as “UploadFilestoSharePointLibrary.Run()” where UploadFilestoSharePointLibrary is the flow name.
  • Add the below formula on Button’s OnSelect property as:
OnSelect = UploadFilestoSharePointLibrary.Run(JSON(colAttachmentGallery,JSONFormat.IncludeBinaryData))

Where,

  1. colAttachmentGallery = Collection name that contains Title and as well as the Data stream value.

Below screenshot is for your reference.

Powerapps upload files to SharePoint library using flow

Step-6:

  • Now just Preview the app and click on the Button (Upload Files to SharePoint Library) and then go to the flow.
  • Open the Flow Run History (My flows -> Select the flow -> Click on ellipses -> Run history). You can see your flow is recently succeded. Open that succeded flow and expand the Compose section as below. Copy the full code from the Output section (we will use this code in the next action).
upload Powerapps files to SharePoint library using microsoft flow
  • Edit the flow and insert the Parse JSON action below the Compose action. Enter the below filed values as:
  1. Content: Go to Dynamic content tab -> Select the Outputs under the Compose section.
  2. Schema: Click on Generate from sample option -> Paste the code that you have copied from the Compose Output section. Once you will paste the code, you can see there are two properties available i.e. one is a DataStream and another one is Title.
Powerapps upload files to SharePoint library using microsoft flow

Step-7:

Next, we will add Apply to each control action under the Parse JSON. Because of the Parse JSON is going to give you an array of object, that’s why we need to apply this control.

  1. Select an output from previous steps: Go to Dynamic content tab -> Select the Body from the Parse JSON action.
upload Powerapps files to SharePoint library using flow

Step-8:

Inside the Apply to each control action, click on Add an action link and insert the Create file action (in SharePoint) as shown below. Enter the field values as:

  1. Site Address: Provide the specific SharePoint site address URL.
  2. Folder Path: Select the SharePoint Document Library (from the Show picker icon) where you are going to upload the Powerapps files.
  3. File Name: Select the Dynamic content -> choose Title under the Parse JSON section.
  4. File Content: Go to the Expression tab and apply the formula as dataUriToBinary(items(‘Apply_to_each’)[‘DataStream’])
how to upload powerapps files to SharePoint library

Step-9:

  • That’s it for the Powerapps flow. Below screenshot represents the total structure of the Microsoft Powerapps flow that we have recently created.
Powerapps upload documents to SharePoint library using flow
  • Now just save the flow and go back to the Powerapps app. Select the button (Upload Files to SharePoint Library) and copy the whole formula (from OnSelect property) and remove it. Again add the flow to the button and paste the same formula on its OnSelect property as like below:
upload Poweraspps documents to SharePoint library using flow

Step-10:

  • Save and Preview (F5) the app. Attach some files (different types of files as image file, Excel file, pdf file etc) to the Powerapps Attachment control. Next, click on the button to upload the files to the SharePoint Document Library.
  • Now check the flow run history, you can see the flow has been completed successfully as shown below. Also, if you will expand the Apply to each action branch, then you can analyze that, it has run 4 times because the output action of JSON has 4 files that I posted from Powerapps to flow.
  • Then it will create the file one by one in the SharePoint Document Library (TSInfo Documents).
Poweraspps upload documents to SharePoint library using flow
  • Next, Open the SharePoint Online Document Library (TSInfo Documents). Then the library will appear with all those four Powerapps files that you have attached in the attachment control as below. You can open any file once you click on it.
how to upload files in Powerapps
powerapps upload image to sharepoint

PowerApps Upload Files to SharePoint Library with different types of Columns

Let us see how to upload multiple files from PowerApps to SharePoint document library.

  • Suppose in SharePoint Document Library, you want to add some extra file information like Document Type, Document Created Date, Department, etc. Then, in that case, you can insert all different types of SharePoint Data columns by using the PowerApps flow.
  • As you can see in my SharePoint Document Library (TSInfo Documents), I have associated with more two columns as Document Type and Department. Both columns are Choice Data type having with these below choice values as:
  1. Document Type: [Private, Public, Confidential, Internal]
  2. Department: [TRAINING, IT, HR, FINANCE]
  • Here what I want to do is, When I will upload the Powerapps files to SharePoint library, at the same time, both choice column values (Document Type and Department) also will add including those files.
  • Follow these below things that we needs to do:

Step-1:

  • Go to the PowerApps app. On the Powerapps screen, Insert two Dropdown controls (Insert -> Input -> Drop down) for two-choice columns.
  • Rename the two dropdown controls to ddDocType and ddDepartment as shown below.

NOTE:

As above are the Choice columns, thats why I have inserted the Dropdown control in Powerapps. Similarly, if there is a Date Time column in SharePoint Library, then you should take a Date Picker control. Also, if there is a text column in SharePoint library, then you should take a Text input control.
upload documents in SharePoint library using powerapps
upload a file to sharepoint from powerapps

Step-2:

  • Now its time to connect the SharePoint Document Library to Powerapps app. Because we need the SharePoint choice values in the Powerapps Dropdown control.
  • That means, when a user will click the dropdown control, then he/she can able to see all the choice values that are coming from the existing SharePoint Document Library.
  • Now to connect the SharePoint Data source connector, Go to View -> Data sources -> search SharePoint -> Add a new or existing SharePoint connection -> Select the SharePoint Site -> Choose the SharePoint Document Library (TSInfo Documents) -> Hit on the Connect button. Then the specific SharePoint Document Library will be added as shown below.
how to upload files in SharePoint library using powerapps

Step-3:

Next, we need to add all the choice values (from SharePoint Library) to the dropdown controls.

  • Select the Document Type Dropdown control and set its Items property as:
Items = Choices('TSInfo Documents'.'Document Type')
  • Similarly, Select the Department Dropdown control and set its Items property as:
Items = Choices('TSInfo Documents'.Department)

You can refer this below screenshot.

upload multiple files in SharePoint library using powerapps flow
powerapps upload multiple files to sharepoint

Step-4:

Open the PowerApps flow that you have recently created. Insert an Initialize variable action below the first Initialize variable (that you created for the files). We need to add this variable action for the Document Type choice column. Enter these below field values as:

  1. Name: Specify a name for the variable (varDocumentType).
  2. Type: Select the type as String from the dropdown.
  3. Value: Go to the Dynamic content tab and click on Ask in PowerApps option under the PowerApps section.
Powerapps upload multiple files to SharePoint Document library using flow

Step-5:

Similarly, add another Initialize variable under the Initialize variable 2 action. We need to add this variable action for the Department choice column. Enter these below field values as:

  1. Name: Specify a name for the variable (varDepartment).
  2. Type: Select the type as String from the dropdown.
  3. Value: Go to the Dynamic content tab and click on Ask in PowerApps option under the PowerApps section.
Powerapps upload files to SharePoint Document library using flow
powerapps upload multiple files to sharepoint

Step-6:

Next, Insert an Update file properties (in SharePoint) action under the Create file action (in apply to each control section). Fill the field values as:

  1. Site Address: Provide the SharePoint Site address URL.
  2. Library Name: Select the SharePoint Document Library (TSInfo Documents) from the Dropdown.
  3. Id: Go to the Dynamic content and select the ItemId from the Create file section.
  4. Document Type Value: Go to the Dynamic content -> Select varDocumentType under the Variables section.
  5. Department Value: Go to the Dynamic content -> Select varDepartment under the Variables section.
upload documents to SharePoint library using Powerapps
upload multiple files from powerapps to sharepoint document library

Step-7:

Now that’s it for doing in the Power Automate. Just Save the flow. This below screenshot represents the total Power Automate structure that I have created to upload the files to SharePoint library.

Powerapps upload document to SharePoint library

Step-8:

  • Now come back to the PowerApps app. Select the button (Upload Files to SharePoint Library), then copy and remove the code from its OnSelect property.
  • Again add the flow to the PowerApps button and paste the code with some more values (on its OnSelect property) like below:
OnSelect = Clear(colAttachmentGallery);
ForAll(
    Gallery1.AllItems,
    Collect(
        colAttachmentGallery,
        {
            Title: lblTitle.Text,
            DataStream: imgDataStream.Image
        }
    )
);
UploadFilestoSharePointLibrary.Run(
    JSON(
        colAttachmentGallery,
        JSONFormat.IncludeBinaryData
    ),
    ddDocType.Selected.Value,
    ddDepartment.Selected.Value
)

Where,

  1. ddDocType = Document Type Dropdown control name
  2. ddDepartment = Department Dropdown control name
Powerapps upload multiple documents to SharePoint library
powerapps upload attachment to sharepoint

Step-9:

  • Save and Preview the app. Attach some files (different types) to the Attachment control.
  • Select the Document type and any Department values from the Dropdown control.
  • Click on the Button (Upload Files to SharePoint Library).
  • Once you will go to the flow and open the Flow run history, then you can see your flow has been succeeded.
Upload multiple documents to SharePoint library in Powerapps
upload multiple files from powerapps to sharepoint document library

Step-10:

  • Now open the SharePoint Document Library (TSInfo Documents). You can see all the Powerapps files have been uploaded including with Document type and Department values as shown below.

NOTE:

Do not forget to delete all the files from the SharePoint Library before you upload again from Powerapps. Otherwise, you may confuse with the uploaded files.
Also, if you forgot to delete the files from the SharePoint library, then attach some new different files in the PowerApps Attachment control and then upload it.
Upload documents to SharePoint library in Powerapps
powerapps upload file to sharepoint document library

Also, you may like these below PowerApps Tutorials:

In this PowerApps Tutorial, We discussed how to upload a file or a document to SharePoint Online Document Library using PowerApps.

Also, We will saw these below things as and ask questions to all your queries:

  • How we can upload and tag multiple files to SharePoint Document Library using PowerApps Attachment control
  • PowerApps upload files to SharePoint Library using Power Automate/Microsoft Flow
  • PowerApps upload files to SharePoint Document Library with a different type of SharePoint columns
  • PowerApps upload file to sharepoint document library
  • PowerApps upload attachment to sharepoint
  • PowerApps upload excel file to sharepoint
  • PowerApps upload multiple files to sharepoint
  • upload multiple files from PowerApps to sharepoint document library
  • PowerApps upload multiple files to sharepoint
  • PowerApps upload image to sharepoint
  • upload a file to sharepoint from PowerApps
  • Great article, thank you. However, I’m experiencing an issue with Step #8. While attempting to add the File Content parameter to the Create File action. I’ve followed your labeling and instructions so I’m using the same names, etc.
    When I attempt to add this text to the File Content field:
    dataUriToBinary(items(‘Apply_to_each’)[‘DataStream’])
    I receive an error message stating “The expression is invalid”. What am I missing?

    • I ran into the same problem. I got around it by choosing Dynamic Content and then choosing the DataStream value from Parse JSON and it appeared to work, at least it copied the files. I need to do some more testing though to see if that will cause some other problem.

    • I think the problem is that you’re cutting and pasting from this website, and the ‘ character gets transformed into an incorrect character. Try manually replacing those and see if it works better for you.

  • Good article – but my flow fails at Step 10

    The Automate step ‘PowerApps’ give the following error “InvokerConnectionOverrideFailed. Failed to parse invoker connections from trigger ‘manual’ outputs. Exception: Could not find any valid connection for connection reference name ‘shared_sharepointonline’ in APIM tokens header.”
    And the same error is also on the buttons. Any assistance welcomed.

  • Brilliant! An absolute lifesaver. After days of looking around and trying to figure this out, your guide is the first one that ties everything together. I used a Logic App instead of a flow, made a few tweaks, and I have files flying into my Azure file share now. I will never understand why microsoft makes this as convoluted as possible. Thanks again!

  • Hello.

    Thank you for a simple guide on how to upload files to a document library using flow. Unfortunately, in step 8, the flow ends with an error:

    Unable to process template language expressions in action ‘Create_file’ inputs at line ‘1’ and column ‘8023’: ‘The template language function’ dataUriToBinary ‘expects its parameter to be formatted as a valid data URI. The provided value ‘appres: // blobmanager / 493b8d139c8b4c34a1c798e8f48faf7d / 3’ was not formatted correctly. Please see https://aka.ms/logicexpressions#dataUriToBinary for usage details. ‘.

    • I think you might have missed the step where you need to convert that blob pointer to the image data stream. An easy clue is the string should not start with “appres: // blobmanager…”, but rather something like “data:image…”

      Hope that helps point you in the right direction.

  • >