Uploading Files to SharePoint Document Library from Power Apps

Scenario:( For Singular File)

In this article, I will show you the easiest way to upload a single file) to a SharePoint document library in Power Apps.

To do this we will use the new Power Apps (V2) trigger in Power Automate which includes the file data type as an input It is no longer necessary to perform a complicated series of steps to transform a file to binary using the JSON function and then back to Base64.

There is no direct Attachment control available in Power apps nowadays, For this we do one workaround add any existing SharePoint list from your SharePoint site.

  • Create a new Edit Form with your SharePoint list as the data source.
  • Cut the attachment control and paste it outside the form. Delete the form.

Use the following properties in the attachments control.

  • Items: Blank()
  • DisplayMode: DisplayMode.Edit

MaxAttachments: 1

Our app now has an attachments field we can use to upload the contract documents. We can now delete the connection to the SharePoint list. It is no longer needed.

Create A Flow To Upload Documents to a SharePoint Library.

Power Automate

Use the PowerApps (V2) trigger because it supports files as an input type

Power Apps

Add a SharePoint action to the flow: Create File. Use your SharePoint site address and document library folder path as inputs. The File Content field should reference the file found in our flow trigger.

Create file

Use the below Expression in the File Name as a value.

triggerBody()['file']['name']

Expression

For file content value select File Content from the dynamic content.

Now flow is ready to upload a document.

Go back to PowerApps and add a button. Select the OnSelect property and click on the UploadFileToDocumentLibrary field in the Power Automate menu.

Tree View

/* For Upload single file*/

UploadFileToDocumentLibrary.Run(
    {

        file: {
            contentBytes: Last(AttachmentControl.Attachments).Value,
            name: Last(AttachmentControl.Attachments).Name
        }
    }
);

We’re done creating the ‘upload a single document to a SharePoint library’ functionality. Test your app to make sure it's working.

Scenario:( For Upload Multiple files)

Just replace the below code with the Upload buttons on selecting Property.

/* For Upload Multiple file*/

ForAll(
    MultiAttachmentControl.Attachments As FILE,
    UploadFileToDocumentLibrary.Run(

        {
            file: {
                contentBytes: FILE.Value,
                name: FILE.Name
            }
        }
    )
);

Thanks for Reading the Blog.

Happy Coding..!