c# - Photo uploaded directly from Camera in Microsoft Teams results always as 403 - Stack Overflow

I have a Bot App running in Microsoft Teams. There I have made this bot able to receive files. Everythi

I have a Bot App running in Microsoft Teams. There I have made this bot able to receive files. Everything works fine if I upload a photo as attachment. Request looks like this:

{
    "attachments": [
        {
            "contentType": "image/*",
            "contentUrl": ";
        },
        {
            "contentType": "text/html",
            "content": "<p><img alt=\"Media\" itemscope=\"\" itemtype=\"\" src=\"\" width=\"2160\" height=\"2880\"></p>"
        }
    ],
    "type": "message",
    "timestamp": "2025-03-13T10:32:32.4231917Z",
    "localTimestamp": "2025-03-13T11:32:32.4231917+01:00",
    "id": "1741861952394",
    "channelId": "msteams",
    "serviceUrl": "/",
    "from": {
        "id": "29:1lS78FUfVVN2WkvaLn8Fls8zpmivS9RxWo974AOv2tRCx31YGchqABn5FeHxzSCm-3n6HdgjDOVCiuxl-Za80qg",
        "name": "Test User",
        "aadObjectId": "33b192a6-0216-47-14599fe0f26a"
    },
    "conversation": {
        "conversationType": "personal",
        "tenantId": "0f6e1639-5b36-450e-95e3-1f",
        "id": "a:1QeVDpdUTPxM_fRgWx3QMckI6mGhTRST6_lBlM1qGRSfiJOJVPCpJ0XKaS3frJEZOcGeo7nyEDWsb0b_hXUXeURwhSGLIqEZfQxlYg1k7pMtZ"
    },
    "recipient": {
        "id": "28:a2670ec4-57d7-4012-9e45-858e",
        "name": "TestBot"
    },
    "entities": [
        {
            "locale": "en-US",
            "country": "US",
            "platform": "Android",
            "timezone": "Europe/Berlin",
            "type": "clientInfo"
        }
    ],
    "channelData": {
        "tenant": {
            "id": "0f6e1639-5b36-450e-95e3-ee40b1f"
        }
    },
    "locale": "en-US",
    "localTimezone": "Europe/Berlin"
}

Then I can normally access the photo and process it further.

However if I do it with camera directly then request looks like this:

{
    "type": "message",
    "timestamp": "2025-03-13T10:30:33.8343393Z",
    "localTimestamp": "2025-03-13T11:30:33.8343393+01:00",
    "id": "174133798",
    "channelId": "msteams",
    "serviceUrl": "/",
    "from": {
        "id": "29:1lS78FUfVVN2WkvaLn8F5FeHxzSCm-3n6Hdgxl-Za80qg",
        "name": "Test User",
        "aadObjectId": "33b192a6-0216-4a96-a467-145926a"
    },
    "conversation": {
        "conversationType": "personal",
        "tenantId": "0f6e1639-5b36-450e-95e3-ef5439e40b1f",
        "id": "a:1QeVDpdUTPxM_fRgWx3QMckIVkunJLFyCAOcC_lBlM1qGRSfiJOJVOcGeo7nyEDWsb0b_hXUxlYg1k7pMtZ"
    },
    "recipient": {
        "id": "28:a2ec4-57d7-4012-9e45-8b48e",
        "name": "Test Bot"
    },
    "entities": [
        {
            "locale": "en-US",
            "country": "US",
            "platform": "Android",
            "timezone": "Europe/Berlin",
            "type": "clientInfo"
        }
    ],
    "channelData": {
        "tenant": {
            "id": "0f6e1639-5b36-450e-95e3-ef5"
        }
    },
    "locale": "en-US",
    "localTimezone": "Europe/Berlin"
}

And I am getting :

{"error":{"code":"BotError","message":"Access Forbidden"}}

and 403.

Was anyone having something similar? I have noticed that while using attachment upload it forwards the files to my sharepoint url which is not the case with directly uploaded photos.

I am trying to get the image like this:

using (HttpClient httpClient = new HttpClient())
{

    var token = await new MicrosoftAppCredentials("MYAPPID", "MYAPPSECRET").GetTokenAsync();
    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    
    var responseMessage = await httpClient.GetAsync(url); // here url is like /...

    var contentLenghtBytes = responseMessage.Content.Headers.ContentLength;
    if (responseMessage.StatusCode == System.Net.HttpStatusCode.OK)
    {
        Console.WriteLine("Done with status '" + responseMessage.StatusCode + "'");
    }

}

It should be simple where I have url of the image and using the token I should be able to get it. But like I said the url is different when the photo is taken directly from the camera. (comparing to one with attachment where we have sharepoint url).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744707194a4589123.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信