cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
mrpowergage
Level: Powered On

Extract image from body of teams message (and convert to base64)

Hi,

 

I'm trying to get an image from the body of a teams message.

 

I know the image is stored in a location similar to this one:

 

https://graph.microsoft.com/beta/teams/eeca1618-16f7-40de-a402-bb1cfce7e9c4/channels/19:31bf2ce9492f...

 

From this URL I want to get the image data and convert it to base64 (if needed) in order to then write it to a CDS record.

 

Any help appreciated, thanks.

8 REPLIES 8
DeepakS
Level 10

Re: Extract image from body of teams message (and convert to base64)

Hi @mrpowergage 

 

Find this similar issue that had a solution in it 

https://powerusers.microsoft.com/t5/General-Power-Automate/How-flow-get-image-from-ms-teams-to-send-...

 

Hope this help.

 

-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

 

mrpowergage
Level: Powered On

Re: Extract image from body of teams message (and convert to base64)

Thanks but I don’t think this is the same issue.

The url is graph not sharepoint, and the image is in the body of the message, not an attachment.
mrpowergage
Level: Powered On

Re: Extract image from body of teams message (and convert to base64)

Any one any ideas on this ? The issue is that the image is not an attachment, it is in the body of the message. See the JSON, the image source is in body.content attachments is empty. When I try and use the URL from the source I get an authentication error.

 

{
    "id": "1584227000439",
    "replyToId": null,
    "etag": "1584227185891",
    "messageType": "message",
    "createdDateTime": "2020-03-14T23:03:20.439Z",
    "lastModifiedDateTime": "2020-03-14T23:06:25.891Z",
    "deletedDateTime": null,
    "subject": null,
    "summary": null,
    "importance": "normal",
    "locale": "en-us",
    "webUrl": "https://teams.microsoft.com/l/message/19%3A31bf2ce9492f45d982681d3f1159657f%40thread.skype/1584227000439?groupId=eeca1618-16f7-40de-a401-bb1cfce7e9c4&tenantId=d838ff12-f626-4a30-b05e-aa4364197307&createdTime=1584227000439&parentMessageId=1584227000439",
    "policyViolation": null,
    "from": {
      "application": null,
      "device": null,
      "conversation": null,
      "user": {
        "id": "7a61d448-27a6-4196-8f7e-80e0aecb1471",
        "displayName": "XXXX",
        "userIdentityType": "aadUser"
      }
    },
    "body": {
      "contentType": "html",
      "content": "<div><div>\n<div>Test stuff<br>\n\n<img src=\"https://graph.microsoft.com/beta/teams/eeca1618-16f7-40de-a401-bb1cfce7e9c4/channels/19:31bf2ce9492f45d982681d3f1159657f@thread.skype/messages/1584227000439/hostedContents/aWQ9LHR5cGU9MSx1cmw9aHR0cHM6Ly91ay1hcGkuYXNtLnNreXBlLmNvbS92MS9vYmplY3RzLzAtc3VrLWQxLWZmMTE1YzZiYmQ1Zjk4MWY3YmM2YmJhMjkyMDBiZjYzL3ZpZXdzL2ltZ28=/$value\" style=\"width:800px; height:600px\"><br>\n\nReport 2 &amp; 3</div>\n</div>\n</div>"
    },
    "attachments": [],
    "mentions": [],
    "reactions": []
  },

 thanks

Re: Extract image from body of teams message (and convert to base64)

hi @mrpowergage  this is the full json? Because as you see the link with src image has a variable called Value.

 

https://graph.microsoft.com/beta/teams/eeca1618-16f7-40de-a401-bb1cfce7e9c4/channels/19:31bf2ce9492f.../$value\

 

So if we don't know what is in value is going to be imposible to get the image.

 

You could use parse json to get the "content": that is in json like this.

getformsImage.gif

mrpowergage
Level: Powered On

Re: Extract image from body of teams message (and convert to base64)

Thanks @ChristianAbata 

 


@ChristianAbata wrote:

hi @mrpowergage  this is the full json? Because as you see the link with src image has a variable called Value.

Yes that's the full json. As you can see the src it is a link to  https://graph.micro.... when I visit that link I get

 

{
  "error": {
    "code": "InvalidAuthenticationToken",
    "message": "Access token is empty.",
    "innerError": {
      "request-id": "2fd192af-c1c6-484a-9f8d-801ce208ed91",
      "date": "2020-03-15T13:25:06"
    }
  }
}

 I'm guessing I need to find a way to authenticate in order to get that data.

 

Any ideas??

Re: Extract image from body of teams message (and convert to base64)

mrpowergage
Level: Powered On

Re: Extract image from body of teams message (and convert to base64)

Many thanks @ChristianAbata 

 

This looks beyond my expertise at this point. I may come back to it, but for now I'm going to find a different way to get the images into the system (probably Kaizala).

 

Thanks for all help.

Re: Extract image from body of teams message (and convert to base64)

@mrpowergage  sure Kaizala is more easy.

Helpful resources

Announcements
firstImage

Better Together Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

firstImage

Incoming: New and improved badges!

Look out for new contribution recognition badges coming SOON!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (4,956)