Building and customizing solutions using Microsoft 365 Copilot APIs and tools
Yeah this sucks, I found the same thing - Microsoft why
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm creating an agent in Copilot Studio and need to retrieve both the file content and file name when a user uploads a .txt file through the chat, then send it to a Flow for processing.
Previously, I used:
Text(First(System.Activity.ChannelData.OriginalAttachments).name) to get the file name
Text(First(System.Activity.ChannelData.OriginalAttachments).ContentUrl) to get the file content
However, Microsoft has now deprecated this structure, and I can no longer retrieve the information as before. I also tried using the File data type, but it didn’t work either.
I have tried many different ways but none of them work.
Is there any new method or workaround to achieve this?
Building and customizing solutions using Microsoft 365 Copilot APIs and tools
Yeah this sucks, I found the same thing - Microsoft why
Hi Nha Tran Huu,
You're correct that Microsoft has deprecated the System.Activity.ChannelData.OriginalAttachments structure. Here's the current approach to handle file uploads in Copilot Studio:
Solution: Using the File Variable Type
In your topic, when you receive a user message with a file:
Once you have the file stored in a variable (e.g., VarFile), you can access:
VarFile.nameVarFile.contentUrlVarFile.sizeVarFile.contentTypeIn your Power Automate flow:
Add inputs for the file data:
- Pass `VarFile.name` to the file name input
- Pass `VarFile.contentUrl` to the content URL input
Alternative: Direct File Handling in Power Automate
If the above doesn't work, try this approach:
In Copilot Studio, pass the entire activity context to Power Automate
In Power Automate, parse the activity JSON:{ "attachments": [ { "contentType": "application/octet-stream", "contentUrl": "https://...", "name": "filename.txt" } ]}
Important Notes:
If you're still having issues, please share:
Hope this helps!
Thanks,
Karan Shewale.
*************************************************************************
If the response is helpful, please click "Accept Answer" and upvote it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.
Hi Charle,
Here's a simple way to handle file uploads from Copilot Studio to Power Automate:
Step 1: Get the file in Copilot Studio Just ask the user to upload a file and save it to a variable (like VarFile). That's it - no extra work needed.
Step 2: Send it to Power Automate Pass that file variable directly to your Power Automate flow.
Step 3: Read the file content In your flow, add a Compose action and use this formula:
base64ToString(triggerBody()?['file']?['contentBytes'])
This converts the file data into readable text that you can actually work with.
Once you have that output, you can save it to another variable or do whatever processing you need.
This approach works with any file type and is much better than the old methods that Microsoft has phased out.
Hope this helps!
Reference: https://learn.microsoft.com/en-us/azure/logic-apps/expression-functions-reference
Hey guys, I found a way that might help you (at least for my .js file):
Upload the file via the agent and store it as variable.
pass the entire file to a flow, no need to do any steps before that.
Now inside the flow:
do a compose like so:
{
"type": "Compose",
"inputs": "@base64ToString(triggerBody()?['file']?['contentBytes'])",
"runAfter": {
"Verfassen": [ <-- This might be different in your studio language
"Succeeded"
]
}
}
and then read the output, you'll see the content of the file. You can also store that in a variable or do what ever you need to do afterwards