Thanks.
The code sample confirmed my suspicion that the problem was
asp.net
converting the form value to a string. After some effort, I came up
with this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
' get the id to associate with the image
If Request.Params("uid") IsNot Nothing Then
File.WriteAllText("c:\temp\test.dat", Request.Params
("uid").ToString())
End If
' if a data form value exists, attempt to read the image
' we cannot just use Request.Form("data") because the data in
this variable has
' been converted to a string
If Request.Form("data") IsNot Nothing Then
Try
' get the request input stream
Dim stream As Stream = Request.InputStream()
Dim x1 As Integer, x2 As Integer
Dim ImageBytes As New List(Of Byte)
' read inital byte
x2 = stream.ReadByte()
' loop until all bytes are read
Do
' get next byte
x1 = stream.ReadByte()
'and exit if none was found
If x1 = -1 Then Exit Do
' are we are still looking for the jpeg header?
If ImageBytes.Count = 0 Then
' yes - see if we have it
If x2 = 255 And x1 = 216 Then
ImageBytes.Add(Convert.ToByte(x2))
ImageBytes.Add(Convert.ToByte(x1))
Else
x2 = x1
End If
Else
' we have found the header, just add bytes
ImageBytes.Add(Convert.ToByte(x1))
End If
Loop
' remove last 20 items from byte list
If ImageBytes.Count > 20 Then ImageBytes.RemoveRange
(ImageBytes.Count - 21, 20)
' create the image
Dim img As Image = Image.FromStream(New MemoryStream
(ImageBytes.ToArray()))
img.Save("c:\temp\test.jpg")
Catch ex As Exception
Dim err As String = ex.Message + vbCrLf +
ex.StackTrace
File.WriteAllText("c:\temp\error.txt", err)
End Try
End If
End Sub
This works, but I am not convinced that there isn't a better way
Cheers
David Ball