【问题标题】:In Microsoft Teams how to save Print Screen -> Ctrl+V images to our custom blob storage在 Microsoft Teams 中,如何将 Print Screen -> Ctrl+V 图像保存到我们的自定义 blob 存储中
【发布时间】:2020-03-28 22:07:44
【问题描述】:

我想在 Microsoft 团队中获取 Print Screen (prtscrn) 并粘贴 (Ctrl+V),此功能正在运行,但我想将粘贴的图像保存到我的自定义存储中。

我参考了这个博客:[1]:https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-and-receive-files?tabs=typescript

但我收到一个错误,因为 此附件没有渲染器

我的问题是,如果我截取屏幕截图并将其粘贴到 Microsoft 团队中,是否可以获取该粘贴的图像并将该图像保存到自定义存储中。

【问题讨论】:

  • 在 Bot 代码中下载图像时是否出错?您能否分享您正在尝试的屏幕截图?

标签: node.js azure blob microsoft-teams


【解决方案1】:

当您在 MS 团队聊天中粘贴图像时,它不会将其视为通常的附件。相反,它作为图像类型接收并将其存储在 MS Team 存储中,并在 Activity.Attachment[0] 中发送图像 URL。

  1. 您必须从该 URL 获取图像并上传到您的 blob 存储。
  2. MS Teams 附件 URL 受 JwtToken 保护,因此我们需要从机器人传递令牌。
  3. 这是一个示例 C# 代码,用于获取图像表单 MS Teams URL 和 将其保存到解决方案文件。您可以在 ActivityHandler 中添加此逻辑 方法。

    if (turnContext.Activity.Attachments != null && turnContext.Activity.Attachments.Count > 1
                && turnContext.Activity.Attachments[0].ContentType=="image/*")
            {
                var attachment = turnContext.Activity.Attachments[0];
                using (HttpClient httpClient = new HttpClient())
                {
                    // MS Teams attachment URLs are secured by a JwtToken, so we need to pass the token from our bot.
                    var token = await new MicrosoftAppCredentials("appId", "password").GetTokenAsync();
                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    var responseMessage = await httpClient.GetAsync(attachment.ContentUrl);
                    var contentLenghtBytes = responseMessage.Content.Headers.ContentLength;
                    // You could not use this response message to fetch the image for further processing.
                    if (responseMessage.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        Stream attachmentStream = await responseMessage.Content.ReadAsStreamAsync();
                        attachmentStream.Position = 0;
                        var image = System.Drawing.Image.FromStream(attachmentStream);
                        image.Save(@"ImageFromUser.png");
                        await turnContext.SendActivityAsync($"Attachment of {attachment.ContentType} type and size of {contentLenghtBytes} bytes received.");
                    }
                }
            }
    

【讨论】:

    猜你喜欢
    • 2010-12-26
    • 2018-10-30
    • 2013-11-13
    • 2017-03-06
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多