The following is the implementation code of a previous function. Now because it needs to be integrated into MVC, I want to rewrite it using MVC. I found that the knowledge is a bit lacking. I really don’t know how to read the binary stream in MVC and then display it in the view. .
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim QstrOffSet As String = Request.QueryString("offs")
If Not String.IsNullOrEmpty(QstrOffSet) Then
Dim FileName As String = Server.MapPath("App_Data\img.dat")
Dim openDataStream As New FileStream(FileName, FileMode.Open, FileAccess.Read)
Dim openDataBR As New BinaryReader(openDataStream)
Try
Dim OffSet As UInt32 = Convert.ToUInt32(QstrOffSet)
openDataStream.Seek(OffSet, SeekOrigin.Begin)
Dim Length As UInt32 = openDataBR.ReadUInt32()
If Length < 33000 Then
Response.ContentType = "application/x-MS-bmp"
Dim myByte() As Byte = openDataBR.ReadBytes(Length)
Response.BinaryWrite(myByte)
End If
Catch ex As Exception
Finally
openDataBR.Close()
openDataStream.Close()
openDataStream.Dispose()
End Try
End If
End If
End Sub
picture
Response.ContentType = "application/x-MS-bmp"
Response.BinaryWrite(myByte)
These two pieces of code should be the key problem. I don’t know what API can handle such problems in MVC. I hope you can help me.
http://stackoverflow.com/questions/7163448/mvc-controller-using-response-stream