byte.eml文件有图像base64编码值..我想在浏览器中打开它...但这不是填充图像文件.... plz帮帮我..
这是代码......
Dim oFile As System.IO.File
Dim或EAD As System.IO.StreamReader
orEAD = oFile.OpenText("E:\mailbox\P3_hemantd.mbx\byte.eml")
Dim content As String
content = ""
''Dim intsinglechr As Integer
''Dim csinglechr As String
While orEAD.Peek <> -1
content = content & Chr(orEAD.Read)
content = Replace(content, vbCrLf, "")
content = Replace(content, vbTab, "")
content = Replace(content, " ", "")
End While
Response.ContentType = "image/jpeg"
Response.BinaryWrite(Convert.FromBase64String(content))
答案 0 :(得分:0)
函数Convert.FromBase64String(content)是否正常工作?尝试写入文件。
答案 1 :(得分:0)
问题是byte.eml
的内容不是base64编码的图像,而是MIME文档。
您需要解析MIME文档,然后获取您的图像。
您可以谷歌“C#MIME MAIL PARSING”。
以下是与您相关的SO question
<强>更新强>:
好的,我们假设你确实有一个有效的图像表示作为base64字符串......
<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim bytes As Byte() = File.ReadAllBytes(Server.MapPath("Chrysanthemum.jpg"))
Dim base64 As String = Convert.ToBase64String(bytes)
'' base64 is what you say you have
Dim newBytes As Byte() = Convert.FromBase64String(base64)
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "image/jpeg"
Response.BinaryWrite(newBytes)
Response.End()
End Sub
</script>
此代码有效,如果您替换base64
的文本并且它不起作用,则表示您没有图像的有效base64字符串表示。
更新2 :
这将读取您说包含base64的文本文件并将其写入响应。
如果它仍然不起作用,那么你还有另一个问题要问:
如何从MIME电子邮件中正确提取base64部分?
<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim base64 As String = File.ReadAllText("E:\mailbox\P3_hemantd.mbx\byte.eml")
Dim newBytes As Byte() = Convert.FromBase64String(base64)
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "image/jpeg"
Response.BinaryWrite(newBytes)
Response.End()
End Sub
</script>