Power Apps: Upload Files to SharePoint Document Library (V2 Trigger Method)

Directly uploading files from Power Apps to a SharePoint Document Library isn’t supported out-of-the-box. However, using the Power Apps (V2) trigger in Power Automate provides a reliable workaround. This guide covers the complete setup.

スポンサーリンク

Step 1: Prerequisites

Before building the app, ensure you have the following ready in SharePoint Online (SPO).

1. Document Library: Create a library where files will be stored.
Create SharePoint Document Library
2. SharePoint List: Create a dummy list.
Why? The Attachment Control in Power Apps is only accessible via a Form control connected to a SharePoint list (or Dataverse table). We need this list solely to grab that control.
Create SharePoint List

Step 2: Create the Power Automate Flow

We will create a flow that receives file data from Power Apps and creates a file in SharePoint.

Note: The screenshots below use the Classic Designer. The steps apply similarly to the New Designer.

1. Create an Instant Cloud Flow and select the PowerApps (V2) trigger.
Power Apps V2 Trigger
2. Add an input parameter of type File.
Add File Parameter

You can rename this parameter (e.g., “FileContent”) for clarity.
Rename Parameter
3. Add the SharePoint “Create file” action.

  • Site Address & Folder Path: Select your target library.
  • File Name: Use the expression triggerBody()['file']['name'] (Dynamic content from the V2 trigger).

SharePoint Create File Action

4. File Content: Select the file content parameter (Bytes) from the trigger.
Set File Content
5. Save the flow. Your backend is ready!
Flow Complete

Step 3: Create the Power Apps UI

Now, let’s extract the Attachment Control.

1. Create a Canvas App and add the SharePoint List connection (from Step 1).
Connect Data Source
2. Insert an Edit Form and connect it to the list.
Insert Edit Form
3. Inside the form, locate the Attachment DataCard. Select the DataCardValue (the attachment control itself) and Cut (Ctrl+X) it.
Cut Attachment Control
4. Paste (Ctrl+V) the control outside the form onto the screen. You can now delete the Form.
Tip: Resolve any errors in the properties pane (remove references to Parent.Default) and set the Items property to blank.
Paste Control

Step 4: Connect Flow to App

1. Add the Power Automate flow to your app.
Add Flow to App
2. Set the MaxAttachments property of the control to 1 (for single file upload).
Set Max Attachments
3. Add a Button and set its OnSelect property to run the flow. Pass the file properties directly:
Button Formula

// Replace 'FlowName' and 'AttachmentControlName' with your actual names
FlowName.Run({
    file: {
        contentBytes: First(AttachmentControlName.Attachments).Value,
        name: First(AttachmentControlName.Attachments).Name 
     }
});

Testing

Run the app, attach a file, and click the button. Check your SharePoint library—the file should appear instantly!
Result in SharePoint

Bonus: Uploading Multiple Files

To handle multiple attachments, we need to loop through the files using ForAll.

1. Change MaxAttachments to your desired limit (e.g., 5).
Max Attachments Multiple
2. Update the button formula:

ForAll(
    AttachmentControlName.Attachments As file,
    FlowName.Run({
        file: { 
            contentBytes: file.Value, 
            name: file.Name
        }
    }) 
);

ForAll Formula

Limitations & Considerations

  • File Size: This method is suitable for small to medium files (typically under 50MB). Larger files may cause the Flow to time out.
  • Overwrite: If a file with the same name exists, SharePoint will overwrite it by default.
  • Performance: Using ForAll triggers a separate Flow run for each file. For bulk uploads, consider passing a JSON array to Flow instead.

While you can also upload files by converting images to Data URI, I prefer the V2 Trigger method for its simplicity and reliability with various file types (PDF, Excel, Docx).

コメント

Copied title and URL