How to Retrieve and Store File Attachments from Copilot Studio Conversations to SharePoint Online with Power Automate

Here’s a note on how to retrieve the content of files attached to conversations.

スポンサーリンク

What I Want to Achieve

This is about retrieving files attached during Copilot conversations and using them in subsequent nodes or tools like Power Automate.
Screenshot showing a file attachment in a Copilot conversation

Attachments Can Be Retrieved from ChannelData

Don’t be fooled by the “Attachments” property in the System Activity – according to the reference site below, attachment information is actually stored in the “ChannelData” property.
How to access user uploaded files in Copilot Studio? - Microsoft Q&A
In Microsoft Copilot Studio, how can I extract and store the text content of a Word or PDF file uploaded by an end user ...
So, when I displayed the contents of ChannelData, I found that the file data (in base64 format) is stored in a property called “OriginalAttachments.”
Screenshot showing ChannelData with OriginalAttachments property containing base64 data

In this example, I’ll use this Base64 data to add file saving functionality to the agent.

Implementation: Saving Attached Files to SharePoint

For this example, we’ll only target the first file that was attached.
*Note: If you want to handle multiple files, don’t use the First function – instead, treat them as a Table or process them in a loop using Foreach.

Building the Power Automate Flow

First, let’s build a Power Automate flow to save the file.

The flow takes the filename and data string as arguments, then uses the “Create file” action to save it. Remember to convert the data string to binary using the base64toBinary function.
Power Automate flow showing the Create file action with base64toBinary conversion
*Note: The File type parameter doesn’t seem to be supported yet for Copilot Studio calls, so create the arguments as “String” type instead.
Screenshot showing argument configuration with String type selected

With that, the Power Automate flow construction is complete.

Building in Copilot Studio

Create a topic and retrieve the “contentUrl” of the first file in ChannelData as a string,
Screenshot showing how to retrieve contentUrl from ChannelData
Use a combination of Split and Index to extract the data string portion from the contentUrl.
Screenshot showing Split and Index functions to extract the data string
Then retrieve the filename,
Screenshot showing how to extract the filename
And pass these to the Power Automate flow we created earlier.
Screenshot showing how to pass the parameters to Power Automate

This completes the implementation.

// Get the contentUrl
Text(First(System.Activity.ChannelData.OriginalAttachments).contentUrl)

// Get the data part
Index(Split(Topic.contentUrl, ","), 2).Value

// Get the file name
Text(First(System.Activity.ChannelData.OriginalAttachments).name)

Testing the Implementation

When you send a file and trigger the topic, the file information is passed to Power Automate,
Screenshot showing the topic being triggered with a file attachment
And the file is successfully saved.
Screenshot showing the successful execution of the Power Automate flow
Screenshot showing the saved file in SharePoint Online

In a future post, I’ll explore using these attached files to build a multimodal agent by combining them with AI Builder.

Related Articles

コメント

Copied title and URL