File Upload control, file loads in VS2008 and server browser, file fails load from client browser across LAN

Win2008 Standard with IIS7.0.

VS2008 website project with grid and upload control in form template.  File upload control loads image file to database blob column for display by grid.

Using Windows authentication for an intranet application.

Image file uploads to the database blob without errors in VS2008 test environment and from the Win2008 server IE7 browser.

Image file does not upload (falls through to CATCH for file not loaded) when file is selected from client IE7browser on LAN or WAN.

I suspect the problem is then with security setup of IIS 7.0 and/or web.config.

Unable to find specifics of requirements to upload files other than the fileupload control documentation.

Appreciate any insight.  Thanks

 

-1
Lannie
11/18/2008 9:00:42 PM
📁 asp.net.security
📃 27051 articles.
⭐ 0 followers.

💬 1 Replies
👁️‍🗨️ 611 Views

I used this concept to solve.

Load image file to byte array and check for file size, file content, etc. as needed to verify it is an image file.

Convert byte array to bitmap

Convert bitmap to thumbnail, use any logic you need for this resizing.

Convert bitmap to memory stream and load into session variable (thumbnail might be 13KB or so in size)

Upload session variable into the BLOB column of the database. 

Private Sub ManageImageFile(ByVal currentUpload As FileUpload)

Dim FileLength As Integer = CInt(currentUpload.PostedFile.InputStream.Length)

Dim FileExtension As String = System.IO.Path.GetExtension(currentUpload.PostedFile.FileName).ToLower()

Dim FileContentType As String = currentUpload.PostedFile.ContentType.ToLower

If FileLength = 0 Then

ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('File has no data. File not uploaded');", True)

Return

ElseIf FileLength > 7168000 Then

ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('File is greater than maximum allowed size of 7 megabytes. File not uploaded.');", True)

Return

End If

Select Case FileContentType

Case "image/pjpeg", "image/jpeg", "image/gif", "image/png"

Case Else

ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('Image formats limited to JPG, GIF, and PNG. File not uploaded.');", True)

Return

End Select

Select Case FileExtension

Case ".jpg", ".gif", ".png"

Case Else

ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('Image formats limited to JPG, GIF, and PNG. File not uploaded.');", True)

Return

End Select

Dim ByteData As Byte() = New Byte(FileLength - 1) {}

Dim MemStream As New MemoryStream()

Dim bitmapWidth As Integer

Dim bitmapHeight As Integer

Dim thumbHeight As Integer

Dim thumbWidth As Integer

Try

currentUpload.PostedFile.InputStream.Read(ByteData, 0, FileLength)

Dim tc As ComponentModel.TypeConverter = ComponentModel.TypeDescriptor.GetConverter(GetType(Bitmap))Dim bitmap As Bitmap = DirectCast(tc.ConvertFrom(ByteData), Bitmap)

bitmapWidth = bitmap.Width

bitmapHeight = bitmap.Height

If bitmapWidth < 100 AndAlso bitmapHeight < 100 Then

thumbWidth = bitmapWidth

thumbHeight = bitmapHeight

Else

thumbWidth = 100

thumbHeight = ((bitmapHeight * 100) / bitmapWidth)

If thumbHeight > 100 Then

thumbWidth = ((bitmapWidth * 100) / bitmapHeight)

thumbHeight = 100

End If

End If

bitmap = DirectCast(bitmap.GetThumbnailImage(thumbWidth, thumbHeight, Nothing, New IntPtr), Bitmap)

bitmap.Save(MemStream, ImageFormat.Jpeg)

Session("DataVB") = MemStream.GetBuffer()

bitmap.Dispose()

MemStream.Close()

Catch

ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('Failed to read file. File not uploaded.');", True)

Return

End Try

End Sub

 

 

-1
Lannie
11/19/2008 7:24:27 PM