How to access user uploaded files in Copilot Studio?

Frank 105 Reputation points
2025-01-12T10:19:26.7933333+00:00

In Microsoft Copilot Studio, how can I extract and store the text content of a Word or PDF file uploaded by an end user via the chat UI (using the attachment icon) into a variable for further processing?

For example, I want to:

  1. Extract the file's text and store it in a variable.
  2. Use this text in a workflow to send it to a private GPT instance with a custom prompt to generate a structured summary.

This question is not related to the "Add Content" feature for knowledge file uploads but focuses on handling files uploaded during live chat interactions.

Any guidance or documentation would be greatly appreciated!

Microsoft Copilot | Other
{count} votes

4 answers

Sort by: Most helpful
  1. Johannes Indbjo 25 Reputation points
    2025-02-25T14:36:24.8666667+00:00

    Hi! I might have a solution, that worked for me.

    The variable System.Activity.ChannelData is what solved it for me. It contains an object called OriginalAttachment that either stores the Base64-file content or an URL to download (if the file is stored in Onedrive).

    Steps to capture channelData

    1. Use a trigger to start the topic, for example that the Activity.Attachments table is not empty.
    2. Set a variable (e.g. attachment_data) to JSON(System.Activity.ChannelData). This variable will become a string. This should happen before any other messages are sent.
    3. Pass the variable to Power Automate.
    4. Parse the variable to a JSON schema with "Analyze Json".
    5. Work with the file content as desired. For example, you can convert the base64-encoded data from contentUrl to binary with base64toBinary in a "Compose". Some connectors need a base64-encoded string anyway. For example, extracting text from a document with AIBuilder to send it to a GPT uses base64-encoded string for the document.

    Otherwise, uploading the file with a Onedrive Connector and First(System.Activity.Attachments).Value and downloading it from Power Automate with the file ID is possible. If you need the filename, it should be in the channelData

    Hope this helps!

    5 people found this answer helpful.

  2. Mcasolaro 25 Reputation points
    2025-03-13T16:46:53.6766667+00:00

    Hello everyone,

    To upload files (as already mentioned by other users), just use the OneDrive connector:
    use the topic "question" with response type "file." Save everything in a variable and use the OneDrive connector to save the file.User's image

    But the problem remains with retrieving the file name and extension.

    By trying to use the solution proposed by another user, you can make a JSON of "System.Activity.ChannelData" and retrieve the file name and content, but there is a 1 MB limit, or CPS gives an error.

    After a thousand attempts, I managed to find a solution and retrieve the file name and its extension:

    User's image

    Simply set a variable in CPS and use this function:

    JSON(First(System.Activity.ChannelData.OriginalAttachments).name)
    

    You can also use "Text()" for direct text

    Text(First(System.Activity.ChannelData.OriginalAttachments).name)
    

    don't worry if the fields are not suggested, just fill it out exactly as written.

    User's image

    3 people found this answer helpful.

  3. Doug Maloney 25 Reputation points
    2025-03-05T03:31:02.36+00:00

    Thanks to my colleague Chris who figured this out.

    Trying to pass a file object directly to a Power Automate flow is a non-starter. You can pass it to a Sharepoint connector directly from Copilotstudio to create a new file - the connector does accept a file object and can create the file.


  4. Matteo Cacciola 0 Reputation points
    2025-06-11T10:44:35.83+00:00

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.