How to send user uploaded file to custom Rest API endpoint?

Nguyen Nhu Phuc 20 Reputation points
2025-06-19T06:34:54.1833333+00:00

Hi technical support team.

We have an existing document intelligence platform to serve out clients. Usually, a user would log in to our platform through out website, upload files to get business insights back.

We are trying to simplify/unify the way our clients use the app, by creating a Microsoft 365 Copilot agent and let the user interact with our platform through this agent. A user would select a starter prompt for a specific task, upload a file and then the agent will send an HTTP request containing the starter prompt and the file to our backend. The main idea is to make use of entraID to skip authentication, our client can just chat with our client through Teams to do what they have been doing.

I've gone through the Copilot bootcamp and several official documentations, however, I couldn't find anything related to this task. The closest I could get to was something like file metadata like this by using Power Fx variable Activity.Attachments in Copilot Studio. It seems that base64 encoded file content is no longer available through this variable.

[{"[
  {
    "Content": {
      "$kind": "FileDataValue",
      "value": {
        "$kind": "ConversationFileReference",
        "value": "9ce2ec8c-4924-40ad-aba2-b849276ca048"
      }
    },
    "ContentType": "application/pdf",
    "Name": "user upload file.pdf",
    "Value": {
      "$kind": "FileDataValue",
      "value": {
        "$kind": "ConversationFileReference",
        "value": "9ce2ec8c-4924-40ad-aba2-b849276ca048"
      }
    }
  }
]


I also tried using declarative agent but it doesn't seem to support forwarding file using HTTP request.

I am trying to debug a custom engine agent using Microsoft 365 Agents Playground but it doesn't allow file upload.

I hope you guys can give me some insights to overcome this issue. Any suggestion or link to documentation is appreciated.

Thank you very much.

Microsoft Copilot Other
{count} votes

Accepted answer
  1. Sayali-MSFT 3,911 Reputation points Microsoft External Staff Moderator
    2025-06-23T11:03:12.1933333+00:00

    Hello @Nguyen Nhu Phuc,You only get a ConversationFileReference (an opaque file reference/token) in Activity.Attachments. You do NOT get the file content or a direct download URL. There is no built-in way to forward the actual file content to your backend via HTTP from a declarative agent.
    Declarative agents and Copilot Studio are currently not suitable for this use case.

    If you need to process file content, Build a custom Teams bot using the Bot Framework SDK (C# or Python). This bot can receive file uploads, download the file using the contentUrl, and send it to your backend.
    Reference Document-https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/bots-filesv4?tabs=csharp1%2Ccsharp

    import aiohttp
    
    async def download_teams_file(content_url, token):
        headers = {"Authorization": f"Bearer {token}"}
        async with aiohttp.ClientSession() as session:
            async with session.get(content_url, headers=headers) as resp:
                if resp.status == 200:
                    return await resp.read()
                else:
                    raise Exception(f"Failed to download file: {resp.status}")
    
    

0 additional answers

Sort by: Most helpful

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.