Hi There,
You can create an automation flow in Power Automate that gets the sharing link of an image file in OneDrive and then posts this link in a Teams chat or channel. However, due to the security restrictions on OneDrive, simply posting a link might not display the image. So, you can use the Graph API to fetch the thumbnail URL of an image and post that in Teams to make the image appear directly. Please follow the steps below:
Step 1: Create a Manual Flow
1. In the Power Automate dashboard, click on "Create" and then "Instant cloud flow".
2. Provide a name for the flow, select "Manually trigger a flow", and click on "Create".
Step 2: Get File Metadata and Content
1. Add a new step and search for "Get file metadata using path" (OneDrive).
2. Choose the appropriate OneDrive account.
3. In the "File Path", specify the path of the image file from which you want to get the metadata.
4. Now, add a new step and search for "Get file content using path" (OneDrive).
5. Choose the same OneDrive account and specify the same path in the "File Path" field.
Step 3: Get Thumbnail URL Using Microsoft Graph API
1. Add a new HTTP step and set the Method as "GET".
2. For the Uri, input `https://graph.microsoft.com/v1.0/me/drive/items/{fileId}/thumbnails`.
- Replace `{fileId}` with the ID of the file, which you can get from the output of the "Get file metadata" step.
3. In Headers, add `Authorization` with the value `Bearer {access_token}`.
- `{access_token}` can be obtained from an OAuth 2.0 authorization step.
4. In the response, you will get a list of thumbnails, from which you can choose any. For example, `body('HTTP')['value'][0]['medium']['url']`.
Step 4: Post Message in Teams
1. Add a new step and search for "Post a message (v3)" (Teams).
2. Choose the Team and Channel where you want to post the image.
3. For the "Message Content", you can use the thumbnail URL obtained from the previous step. You can use the format `<img src="{thumbnail_url}" />` to display the image in the message.
Remember to save your flow. Now, whenever you run this flow, it will fetch the image from OneDrive and post it to the specified Teams chat or channel. Be sure to replace placeholders like `{fileId}`, `{access_token}`, and `{thumbnail_url}` with their actual values in the respective steps.
Please give me kudos and make as solution if it helps.
Thanks,
Sandeep Mishra