【问题标题】:GitHub Readme.md markdown file data-canonical-src issue with image srcGitHub Readme.md markdown 文件 data-canonical-src 与图像 src 的问题
【发布时间】:2020-11-08 08:10:36
【问题描述】:

我有一个 azure 函数,可以从我的提要中返回我的热门博客的图像。现在我刚刚将该函数 URL 作为图像 src 添加到 Readme.md 文件中,如下所示。

<img src="https://getlatestposts.azurewebsites.net/api/GetLatestPosts?code=VS4fy5DNxpj8/SUS0Chp0aGBux36c9OyOg5KhmSjh5dPVBvCaVaEuA==">

但是图像根本没有加载,当我检查生成的 HTML 时,我可以看到 src 已使用来自“https://camo.githubusercontent.com”的一些奇怪的 URL 进行了更新。另外还介绍了一个a tag

还有其他人遇到过这个问题吗?

【问题讨论】:

  • 您确定您的图片链接是公开的吗?因为当我尝试它时,它会抛出“没有找到与请求匹配的 HTTP 资源”
  • @Amacado 好吧,我在 SO 中给出了一个虚拟 URL。我的原始 URL 返回 base64 字符串,我可以将它手动应用到任何图像 src,它工作正常。
  • 请向我们展示您的降价,以便我们可以复制它.. base64 样本也很好
  • 也许这有帮助? superuser.com/questions/1199393/…
  • @Amacado 我已经用实际功能更新了 src。

标签: github automation azure-functions markdown readme


【解决方案1】:

最后,我能够解决这个问题。我所做的是,我从我的 Azure 函数返回了一个 File Stream,而不是返回一个 base64 字符串。下面是我的 Azure 函数。

[FunctionName("GetLatestPosts")]
public static FileStreamResult Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest request, ILogger log) {
    try {
        var baseString = WriteOnImage(GetLatestFeeds());
        // Had to do this, as it was throwing error "The input is not a valid Base-64 string as it contains a non-base 64 character"
        string convert = baseString.Replace("data:image/png;base64,", String.Empty);
        var bytes = Convert.FromBase64String(convert);
        var result = new FileStreamResult(new MemoryStream(bytes), Configuration.ContentType);
        log.LogInformation("Returning stream now!");
        request.HttpContext.Response.Headers.Add("Cache-Control", "s-maxage=1, stale-while-revalidate");
        return result;;
    } catch (System.Exception ex) {
        log.LogError($ "Something went wrong: {ex}");
        throw ex;
    }
}

我确实写了一篇关于整个应用程序的文章,你可以阅读它here。它还包含 GitHub 存储库,以防万一,如果您有兴趣。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 2011-11-26
    • 1970-01-01
    相关资源
    最近更新 更多