在 MVC2 中显示图像 blob

发布于 2024-10-10 17:03:37 字数 8645 浏览 0 评论 0原文

我正在尝试(但没有成功)从服务中获取 blob 图像并将其显示为 html 中的图像。

我的 html 是:

<img src="<%: Url.Action("GetPersonImage", new { pid = Model.PersonId }) %>" alt="" />

女巫在 Source 中显示,因为

<img src="/demo4/ABook/GetPersonImage/?pid=210092" alt="">

我的操作是:

    public void GetPersonImage(int pid)
    {
        string src = so.GetPersonImage(pid);
        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(src);

        Response.Clear();
        Response.AddHeader("Content-Length", src.Length.ToString());
        Response.ContentType = "image/gif";
        Response.BufferOutput = false;
        Response.BinaryWrite(bytes);
        Response.End();
    }

则页面中不会显示任何内容

如果我访问http://localhost:60556/demo4/ABook/GetPersonImage/?, ? pid=210092

我什至尝试使用 FileStreamResult

    public FileStreamResult GetPersonImage(int pid)
    {
        string src = so.GetPersonImage(pid);

        Response.Clear();
        Response.Expires = 0;
        Response.AddHeader("Content-Length", src.Length.ToString());
        Response.BufferOutput = false;

        return new FileStreamResult(
                        new System.IO.MemoryStream(
                            System.Text.Encoding.UTF8.GetBytes(src)), "image/gif");
    }

但仍然没有:(

src 变量包含

iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAEAAAIAAIAAAACAAcAAAIAAAAPAAAZAABABgAsAAAnAAA/BgU4AQREBgBKCQpIExMAAB0AACQAACImABI1ABdKCSMyAB9DBSwYAD cnAEUOAEYlAEA1CRMREiUjJCU/DjQNFEpTKjc1Nks5UULHSAAATwAAUgACVgAATQECTgADVQARYQAgbQAkcQA UZGAYZwaAebAAkcwArdwAueQAxfAA3gQAtegA2gAA4gwA8hgA+hwAseQAzfQA5hABFiwaAHWgALXAARYAAGWAAK XAIHVwIXZAYaABCjABJkQBLkA0KTRAPVRMXYgwbaBkTTSAcWiYcTyEgZRMncCQpbQ41ehs0eixMizIoTy8oXz40Y0AwUExCaE5HbzU2eEZJggBODgBXHQBjFgBGIABQDABlFgBiKwB7HwBiFQBtoOhN3RyWCV wBPlQBUmQBanQBgoQBhpABnqABTlgBeoABsqgBzrwBvrAB4sQN8tQ1/uBp/txeHvTNYkziKZVdZjkuXdV6hgh10qyGNwCyTwjWYxkCdyjtknkNwpkt7r1KIuFuTwEmizFon0F6r01QXAFEe AFwbAGMkAGgrA28zC3U6DmJNIG42EVhEUWVNUXJXUntCG4RLIoFRL4dNHI5YLlxQbGxoQZRdKpRhOH9fUotoVI9iQ5RsVJdwVaBqN6VxO55sQ6d5TKB2VKR7U6J7Xq+CV69/XbGFVK6EXri ITrNYb6PVcWaZFpYWW1gcGZpmIKkjYd0e5x6Y5aCf5GPkJ2diaKionZ6pIeJrpiZuaiqxW+skXm pkIK1oGur02iy13K525S/r6fLvaJ+ZKmFa6qMeLaZh76Va8aedsafgbafjMClksmfa8ylcm+nd8+ qgcywl8q1ptOsfdKuhtWxgde0itu4jNCyjtK3mN69ktm9m9TAq9nFrt/AleHCmuLJp7W1tcu/tbm8z8rJ2rnVzMHTyc3e2dTEud3RyeTQt+bVwObbzeLg39vb5d7q6Onv8+fg2uvq7u/19/Hu 6/7+/gAAAAAAADLRNusAAAEAdFJOU///// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// ///////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAQhElEQVR4Xu1ae3gU1RWHVcC2Sl/WPuhbs9wQI1SWaghUA1tIBIsN9UnDSqtRJI8+1bZQi7YIynpn2 AadXVeNTWJ3a1KaTIxfhBqwAmnDsiGrrKAbCmWTAtZNCNpks9/Xc++d2Z2Z3Z2ZQNR/ej4fyczsnN/9nd953LuZkPiQbcKH7D/ xfwDjzcDIrnVlaHmH+cCOL4B31yE0o/R6hJabRjCeAIj70oc7Ozs3zUCmOR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TgiKJQKN73SxIxxqSxAQeV evshgZJaRKa0tuEX0GKpvRqPRiNZIlhOdRhjlelG/Xu8qt7h6Q7KOMyARGsf0xjCCAhyPOVXx0EAfP +DAUAHMOIyCVx+dTNL41iYwChpJwEFYJwMMthKRlR2b6EJKHR7tQYwAgvUwBvdmdes1KCTaDLpP+om zf40SAYAIzFyYwCblPvTpM+Yb+JDN1UVrQYnhSaAJCokYtaNALjd7bIQ9n3wy4Acz7yxbasRsPTYjMAYnIiwFvprACTbzIlYdZq8flIyaRpoYbnMlagSNIMgerXStQAgZS+zAbHpyphenGP0TGhOQCjgkslvq CPTGxJcwmC2+dTnRVLNdDEdzamGEgMJDMhk/KyXIOOaXxab46BROKQphMwn+k9QIEF/Bv8OSkNjzkG EolQJgRuIVMhlnuQmfWbB5BoyIAg4uJqs7Bgcv1jAAAIBKUSmdx9nHpOkuMap0cm4j+WEMCzDZhXNG SDLQEZFkzFf4wAoCbj2iQJOpsi6Blm1z+WEADCEI95uRdk/6uWIIcbzOif1SizWcCepqcnDMKWLDEg7cL4q6qs23OjyjnSret9OHqUO5Cx/ka35HUO5dLfPzYGCakeOorVOhu180jETVuVwrcU Y54J0zEPNND9tkcLwOsC9tO3PgakjpkB+r7Y/oBNS78aAZwa4roxsX8WILSsJoSPqwH4xqS95J vOjgH4+DDep84DHpusfeqYnDWAhGeL6nyiBZto/hn0cPYAQnCAqAiCoD2BNMpo6f7ZA0ju8LFU OdQe/5l0P9ZKqHotnGjFklFwnSUBYyzF6nV1Od2xodNUil6DHWB2Qs4hBKRBb4Hvs4YGj7mx+uzNdADOKQTgZT/vFBob66D +m/rLuUy4zokBqAbwzR6cpIyh/Y5DL9C8As5/xsB42qPnyMC5uGaf/dAB/A/iHFyQC+PfuwAAAABJRU5ErkJggg==

缺少什么?

I'm trying (without success) to fetch a blob image from a service and show it as an image in html.

my html is:

<img src="<%: Url.Action("GetPersonImage", new { pid = Model.PersonId }) %>" alt="" />

witch shows in the Source as

<img src="/demo4/ABook/GetPersonImage/?pid=210092" alt="">

my action is:

    public void GetPersonImage(int pid)
    {
        string src = so.GetPersonImage(pid);
        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(src);

        Response.Clear();
        Response.AddHeader("Content-Length", src.Length.ToString());
        Response.ContentType = "image/gif";
        Response.BufferOutput = false;
        Response.BinaryWrite(bytes);
        Response.End();
    }

and this shows nothing in the page if I access to

http://localhost:60556/demo4/ABook/GetPersonImage/?pid=210092

I even tried with FileStreamResult

    public FileStreamResult GetPersonImage(int pid)
    {
        string src = so.GetPersonImage(pid);

        Response.Clear();
        Response.Expires = 0;
        Response.AddHeader("Content-Length", src.Length.ToString());
        Response.BufferOutput = false;

        return new FileStreamResult(
                        new System.IO.MemoryStream(
                            System.Text.Encoding.UTF8.GetBytes(src)), "image/gif");
    }

and still nothing :(

the src variable contains

iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAEAAAIAAIAAAACAAcAAAIAAAAPAAAZAABABgAsAAAnAAA/BgU4AQREBgBKCQpIExMAAB0AACQAACImABI1ABdKCSMyAB9DBSwYADcnAEUOAEYlAEA1CRMREiUjJCU/DjQNFEpTKjc1Nks5UUlHSAAATwAAUgACVgAATQECTgADVQARYQAgbQAkcQAUZgAYZwAebAAkcwArdwAueQAxfAA3gQAtegA2gAA4gwA8hgA+hwAseQAzfQA5hABFiwAHWgALXAARYAAGWAAKXAIHVwIXZAAYaABCjABJkQBLkA0KTRAPVRMXYgwbaBkTTSAcWiYcTyEgZRMncCQpbQ41ehs0eixMizIoTy8oXz40Y0AwUExCaE5HbzU2eEZJggBODgBXHQBjFgBgIABQDABlFgBiKwB7HwBiFQBtOhN3RyWCVwBPlQBUmQBanQBgoQBhpABnqABTlgBeoABsqgBzrwBvrAB4sQN8tQ1/uBp/txeHvTNYkziKZVdZjkuXdV6hgh10qyGNwCyTwjWYxkCdyjtknkNwpkt7r1KIuFuTwEmizFOn0F6r01QXAFEeAFwbAGMkAGgrA28zC3U6DmJNIG42EVhEUWVNUXJXUntCG4RLIoFRL4dNHI5YLlxQbGxoQZRdKpRhOH9fUotoVI9iQ5RsVJdwVaBqN6VxO55sQ6d5TKB2VKR7U6J7Xq+CV69/XbGFVK6EXriITraNYb6PVcWaZFpYWW1gcGZpmIKkjYd0e5x6Y5aCf5GPkJ2diaKionZ6pIeJrpiZuaiqxW+skXmpkIK1oGur02iy13K525S/r6fLvaJ+ZKmFa6qMeLaZh76Va8aedsafgbafjMClksmfa8ylcM+nd8+qgcywl8q1ptOsfdKuhtWxgde0itu4jNCyjtK3mN69ktm9m9TAq9nFrt/AleHCmuLJp7W1tcu/tbm8z8rJ2rnVzMHTyc3e2dTEud3RyeTQt+bVwObbzeLg39vb5d7q6Onv8+fg2uvq7u/19/Hu6/7+/gAAAAAAADLRNusAAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAQhElEQVR4Xu1ae3gU1RWHVcC2Sl/WPuhbs9wQI1SWaghUA1tIBIsN9UnDSqtRJI8+1bZQi7YIynpn2AadXVeNTWJ3a1KaTIxfhBqwAmnDsiGrrKAbCmWTAtZNCNpks9/Xc++d2Z2Z3Z2ZQNR/ej4fyczsnN/9nd953LuZkPiQbcKH7D/xfwDjzcDIrnVlaHmH+cCOL4B31yE0o/R6hJabRjCeAIj70oc7Ozs3zUCmORhHAB12VLoR3INtRHazFIwbgJEyZCer3/vQfT+qrl6ITplEMF4ATtnRjXs6OzffD97BZqGTKgD/zQpnnADssqPfwervp97BCj9gALvQDIj+g2z1xBZ9sCEA/5s6N9+bdF9dbX2/RLhr5XJ72Tp1fBPUv2L51dXz0TqTGszWC06dJKZV8shyxKzsXcX7T9lnbNp7n2L51ZVWjQR00GQQ4bs7yyQ/4OlFJYjl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yPOVXx0EAfP+DAUAHMOIyCVx+dTNL41iYwChpJwEFYJwMMthKRlR2b6EJKHR7tQYwAgvUwBvdmdes1KCTaDLpP+omzf40sAYAIzFyYwCblPvTpM+Yb+JdN1UVrQYnhSaAJCokYtaNALjd7bIQ9n3wy4Acz7yxbasRsPTYjMAYnIiwFvprACTbzIlYdZq8flIyaRpoYbnMlAgSNIMgERXStQAgZS+zAbHpyphenGP0TGhOQCjgkslvqCPTGxJcwmC2+dTnRVLNdDEdzamGEgMJDMhk/KyXIOOaXxab46BROKQphMwn+k9QIEF/Bv8OSkNjzkGEolQJgRuIVMhlnuQmfWbB5BoyIAg4uJqs7Bgcv1jAAAIBKUSmdx9nHpOkUMAp0cm4j+WEMCzDZhXNGSdLQEZFkzFf4wAoCbj2iQJOpsi6Blm1z+WEADcEI95uRdk/6uWIIcbzOif1SizWcCepqcnDMKWLDEg7cL4q6qs23OjyjnSRet9OHqUO5Cx/kA35HUO5dLfPzYGCAkeOorVOhu180jETVuVwRcUY54J0zEPNND9tkcLwOsC9tO3PgakjpkB+r7Y/oBnS78aAZwa4roxsX8WIlSsJoSPqwH4xqS95JvOjgH4+DDep84DHpusfeqYnDWAhGeL6nyiBZto/hn0cPYAQnCAqAiCoD2BNMpo6f7ZA0jU8LFUOdQe/5l0P9ZKqHotnGjFklFwnSUBYyzF6nV1Od2xodNUil6DHWB2Qs4hBKRBb4Hvs4YGj7mx+uzNdADOKQTgZT/vFBob66D+m/rLuUy4zokBqAbwzR6cpIyh/Y5DL9C8As5/xsB42qPnyMC5uGaf/dAB/A/iHFyQC+PfuwAAAABJRU5ErkJggg==

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红ご颜醉 2024-10-17 17:03:37

您的字符串包含 base64 数据,而不是 UTF8 字符,因此您需要使用 Convert.FromBase64String。另外,Content-Length 应该是二进制数据的长度,而不是字符串的长度。

public FileStreamResult GetPersonImage(int pid)
{
    string src = so.GetPersonImage(pid);
    byte[] imageBytes = Convert.FromBase64String(src);
    MemoryStream ms = new MemoryStream(imageBytes);

    Response.Clear();
    Response.Expires = 0;
    Response.AddHeader("Content-Length", imageBytes.Length.ToString());
    Response.BufferOutput = false;

    return new FileStreamResult(ms, "image/png");
}

Your string contains base64 data, not UTF8 characters, so you need to use Convert.FromBase64String. Also, the Content-Length should be the length of the binary data, not the length of the string.

public FileStreamResult GetPersonImage(int pid)
{
    string src = so.GetPersonImage(pid);
    byte[] imageBytes = Convert.FromBase64String(src);
    MemoryStream ms = new MemoryStream(imageBytes);

    Response.Clear();
    Response.Expires = 0;
    Response.AddHeader("Content-Length", imageBytes.Length.ToString());
    Response.BufferOutput = false;

    return new FileStreamResult(ms, "image/png");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文