All methods to get content files in copilot studio are not working.

Nha Tran Huu 5 Reputation points
2025-07-19T06:30:57.5033333+00:00

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.

User's image

User's image

User's image

User's image

Is there any new method or workaround to achieve this?

Microsoft Copilot | Microsoft 365 Copilot | Development
{count} vote

3 answers

Sort by: Most helpful
  1. Karan Shewale 1,040 Reputation points Microsoft External Staff
    2025-07-21T13:54:09.1566667+00:00

    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

    1. Configure File Upload in Your Topic

    In your topic, when you receive a user message with a file:

    • The system should automatically detect the file upload
    • Use the "Save user response as" option and select File as the variable type
    1. Access File Properties

    Once you have the file stored in a variable (e.g., VarFile), you can access:

    • File nameVarFile.name
    • File content URLVarFile.contentUrl
    • File sizeVarFile.size
    • File typeVarFile.contentType
    1. Pass to Power Automate

    In your Power Automate flow:

    Add inputs for the file data:

    • Add a text input for the file name
      • Add a text input for the content URL
      In Copilot Studio, when calling the flow:
      - Pass `VarFile.name` to the file name input
      
         - Pass `VarFile.contentUrl` to the content URL input
      
    1. In Power Automate, retrieve the file content: HTTP Action: - Method: GET - URI: {contentUrl from input} - Authentication: Use appropriate auth based on your environment

    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:

    • Ensure your Copilot Studio environment is updated to the latest version
    • The File variable type should automatically capture uploads
    • If files aren't being detected, check your channel configuration (Teams, Web Chat, etc.)

    If you're still having issues, please share:

    1. Which channel you're using (Teams, Web Chat, etc.)
    2. The exact error or behavior you're seeing
    3. A screenshot of your topic configuration

    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. 

    1 person found this answer helpful.

  2. Anne Admin 6 Reputation points
    2025-07-25T07:04:59.73+00:00

    Yeah this sucks, I found the same thing - Microsoft why

    0 comments No comments

  3. Morten 0 Reputation points
    2025-07-28T08:13:58.3233333+00:00

    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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.