473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Unable to upload images larger than 131 071 bytes

Hi. I'm letting the users upload images into a sybase 12.5 database. The
problem is that when ContentLength exceeds 131 071 an exception occur. The
e.Message property is empty so it doesn't tell me much. I know that images
much larger than this exist in the database. Any help is appreciated! Here
is my code:

Dim cn As New Connection
Dim oleDbCommand As OleDbCommand
Dim strSqlImage As String
Dim stream As System.IO.Stream = textBoxImage.PostedFile.InputStream
Dim intFileLength As Integer = textBoxImage.PostedFile.ContentLength
Dim byteArray(intFileLength) As Byte

cn.Open()

stream.Read(byteArray, 0, intFileLength)

strSqlImage = "UPDATE TABLE1 SET image = ? WHERE id = " & intID

oleDbCommand = New OleDbCommand(strSqlImage, cn.oleDbConnection)
oleDbCommand.Parameters.Add(New OleDbParameter("@image",
OleDbType.LongVarBinary)).Value = byteArray

oleDbCommand.ExecuteNonQuery()
Nov 19 '05 #1
6 1822
Shawn:

You'll want to check the value of maxRequestLength in web.config or machine.config.
It sounds as if the default value has been overridden but perhaps you'll
need to bump it up higher.

See:
PRB: Cannot Upload Large Files When You Use the HtmlInputFile Server Control
http://support.microsoft.com/default...b;en-us;295626

--
Scott
http://www.OdeToCode.com/blogs/scott/
Hi. I'm letting the users upload images into a sybase 12.5 database.
The problem is that when ContentLength exceeds 131 071 an exception
occur. The e.Message property is empty so it doesn't tell me much. I
know that images much larger than this exist in the database. Any help
is appreciated! Here is my code:

Dim cn As New Connection
Dim oleDbCommand As OleDbCommand
Dim strSqlImage As String
Dim stream As System.IO.Stream = textBoxImage.PostedFile.InputStream
Dim intFileLength As Integer = textBoxImage.PostedFile.ContentLength
Dim byteArray(intFileLength) As Byte
cn.Open()

stream.Read(byteArray, 0, intFileLength)

strSqlImage = "UPDATE TABLE1 SET image = ? WHERE id = " & intID

oleDbCommand = New OleDbCommand(strSqlImage, cn.oleDbConnection)
oleDbCommand.Parameters.Add(New OleDbParameter("@image",
OleDbType.LongVarBinary)).Value = byteArray

oleDbCommand.ExecuteNonQuery()

Nov 19 '05 #2
The problem isn't uploading bigger files to the server, it's inserting them
into the DB.

Shawn
"Scott Allen" <sc***@nospam.OdeToCode.com> wrote in message
news:55*********************@msnews.microsoft.com. ..
Shawn:

You'll want to check the value of maxRequestLength in web.config or machine.config. It sounds as if the default value has been overridden but perhaps you'll
need to bump it up higher.

See:
PRB: Cannot Upload Large Files When You Use the HtmlInputFile Server Control http://support.microsoft.com/default...b;en-us;295626

--
Scott
http://www.OdeToCode.com/blogs/scott/
Hi. I'm letting the users upload images into a sybase 12.5 database.
The problem is that when ContentLength exceeds 131 071 an exception
occur. The e.Message property is empty so it doesn't tell me much. I
know that images much larger than this exist in the database. Any help
is appreciated! Here is my code:

Dim cn As New Connection
Dim oleDbCommand As OleDbCommand
Dim strSqlImage As String
Dim stream As System.IO.Stream = textBoxImage.PostedFile.InputStream
Dim intFileLength As Integer = textBoxImage.PostedFile.ContentLength
Dim byteArray(intFileLength) As Byte
cn.Open()

stream.Read(byteArray, 0, intFileLength)

strSqlImage = "UPDATE TABLE1 SET image = ? WHERE id = " & intID

oleDbCommand = New OleDbCommand(strSqlImage, cn.oleDbConnection)
oleDbCommand.Parameters.Add(New OleDbParameter("@image",
OleDbType.LongVarBinary)).Value = byteArray

oleDbCommand.ExecuteNonQuery()


Nov 19 '05 #3
haven't used sybase in awhile, but you used to have "set textsize" for arge
text or images, as it defautled to 32k.

-- bruce (sqlwork.com)

"Shawn" <bo********@hotmail.com> wrote in message
news:Oq**************@TK2MSFTNGP10.phx.gbl...
| The problem isn't uploading bigger files to the server, it's inserting
them
| into the DB.
|
| Shawn
|
|
| "Scott Allen" <sc***@nospam.OdeToCode.com> wrote in message
| news:55*********************@msnews.microsoft.com. ..
| > Shawn:
| >
| > You'll want to check the value of maxRequestLength in web.config or
| machine.config.
| > It sounds as if the default value has been overridden but perhaps you'll
| > need to bump it up higher.
| >
| > See:
| > PRB: Cannot Upload Large Files When You Use the HtmlInputFile Server
| Control
| > http://support.microsoft.com/default...b;en-us;295626
| >
| > --
| > Scott
| > http://www.OdeToCode.com/blogs/scott/
| >
| > > Hi. I'm letting the users upload images into a sybase 12.5 database.
| > > The problem is that when ContentLength exceeds 131 071 an exception
| > > occur. The e.Message property is empty so it doesn't tell me much. I
| > > know that images much larger than this exist in the database. Any help
| > > is appreciated! Here is my code:
| > >
| > > Dim cn As New Connection
| > > Dim oleDbCommand As OleDbCommand
| > > Dim strSqlImage As String
| > > Dim stream As System.IO.Stream = textBoxImage.PostedFile.InputStream
| > > Dim intFileLength As Integer = textBoxImage.PostedFile.ContentLength
| > > Dim byteArray(intFileLength) As Byte
| > > cn.Open()
| > >
| > > stream.Read(byteArray, 0, intFileLength)
| > >
| > > strSqlImage = "UPDATE TABLE1 SET image = ? WHERE id = " & intID
| > >
| > > oleDbCommand = New OleDbCommand(strSqlImage, cn.oleDbConnection)
| > > oleDbCommand.Parameters.Add(New OleDbParameter("@image",
| > > OleDbType.LongVarBinary)).Value = byteArray
| > >
| > > oleDbCommand.ExecuteNonQuery()
| > >
| >
| >
|
|
Nov 19 '05 #4
Apologies.

--
Scott
http://www.OdeToCode.com/blogs/scott/
The problem isn't uploading bigger files to the server, it's inserting
them into the DB.

Shawn

"Scott Allen" <sc***@nospam.OdeToCode.com> wrote in message
news:55*********************@msnews.microsoft.com. ..
Shawn:

You'll want to check the value of maxRequestLength in web.config or

machine.config.
It sounds as if the default value has been overridden but perhaps
you'll need to bump it up higher.

See:
PRB: Cannot Upload Large Files When You Use the HtmlInputFile Server

Control
http://support.microsoft.com/default...b;en-us;295626

--
Scott
http://www.OdeToCode.com/blogs/scott/
Hi. I'm letting the users upload images into a sybase 12.5 database.
The problem is that when ContentLength exceeds 131 071 an exception
occur. The e.Message property is empty so it doesn't tell me much. I
know that images much larger than this exist in the database. Any
help is appreciated! Here is my code:

Dim cn As New Connection
Dim oleDbCommand As OleDbCommand
Dim strSqlImage As String
Dim stream As System.IO.Stream = textBoxImage.PostedFile.InputStream
Dim intFileLength As Integer = textBoxImage.PostedFile.ContentLength
Dim byteArray(intFileLength) As Byte
cn.Open()
stream.Read(byteArray, 0, intFileLength)

strSqlImage = "UPDATE TABLE1 SET image = ? WHERE id = " & intID

oleDbCommand = New OleDbCommand(strSqlImage, cn.oleDbConnection)
oleDbCommand.Parameters.Add(New OleDbParameter("@image",
OleDbType.LongVarBinary)).Value = byteArray

oleDbCommand.ExecuteNonQuery()

Nov 19 '05 #5
I tried setting textsize to a larger number, but I still get an error.
"bruce barker" <no***********@safeco.com> wrote in message
news:e0**************@TK2MSFTNGP15.phx.gbl...
haven't used sybase in awhile, but you used to have "set textsize" for arge text or images, as it defautled to 32k.

-- bruce (sqlwork.com)

"Shawn" <bo********@hotmail.com> wrote in message
news:Oq**************@TK2MSFTNGP10.phx.gbl...
| The problem isn't uploading bigger files to the server, it's inserting
them
| into the DB.
|
| Shawn
|
|
| "Scott Allen" <sc***@nospam.OdeToCode.com> wrote in message
| news:55*********************@msnews.microsoft.com. ..
| > Shawn:
| >
| > You'll want to check the value of maxRequestLength in web.config or
| machine.config.
| > It sounds as if the default value has been overridden but perhaps you'll | > need to bump it up higher.
| >
| > See:
| > PRB: Cannot Upload Large Files When You Use the HtmlInputFile Server
| Control
| > http://support.microsoft.com/default...b;en-us;295626
| >
| > --
| > Scott
| > http://www.OdeToCode.com/blogs/scott/
| >
| > > Hi. I'm letting the users upload images into a sybase 12.5 database.
| > > The problem is that when ContentLength exceeds 131 071 an exception
| > > occur. The e.Message property is empty so it doesn't tell me much. I
| > > know that images much larger than this exist in the database. Any help | > > is appreciated! Here is my code:
| > >
| > > Dim cn As New Connection
| > > Dim oleDbCommand As OleDbCommand
| > > Dim strSqlImage As String
| > > Dim stream As System.IO.Stream = textBoxImage.PostedFile.InputStream
| > > Dim intFileLength As Integer = textBoxImage.PostedFile.ContentLength
| > > Dim byteArray(intFileLength) As Byte
| > > cn.Open()
| > >
| > > stream.Read(byteArray, 0, intFileLength)
| > >
| > > strSqlImage = "UPDATE TABLE1 SET image = ? WHERE id = " & intID
| > >
| > > oleDbCommand = New OleDbCommand(strSqlImage, cn.oleDbConnection)
| > > oleDbCommand.Parameters.Add(New OleDbParameter("@image",
| > > OleDbType.LongVarBinary)).Value = byteArray
| > >
| > > oleDbCommand.ExecuteNonQuery()
| > >
| >
| >
|
|

Nov 19 '05 #6
Scott, I stumbled onto this post and think I'm missing something here. I
reviewed the article you list but am expericing an error when I go over
4KB??? I'm saving to SQl Server 2K, field is image. Nothing set in webconfig,
etc.
Any ideas?

Code:
Dim iLength As Integer = CType(inpFileUp.PostedFile.InputStream.Length,
Integer)
If iLength = 0 Then Exit Sub 'not a valid file
Dim sContentType As String = inpFileUp.PostedFile.ContentType
Dim sFileName As String, i As Integer
Dim bytContent As Byte()
ReDim bytContent(iLength) 'byte array, set to file size
'strip the path off the filename
i = InStrRev(inpFileUp.PostedFile.FileName.Trim, "\")
If i = 0 Then
sFileName = inpFileUp.PostedFile.FileName.Trim
Else
sFileName = Right(inpFileUp.PostedFile.FileName.Trim,
Len(inpFileUp.PostedFile.FileName.Trim) - i)
End If

Try
inpFileUp.PostedFile.InputStream.Read(bytContent, 0, iLength)

Response.Write("filesize = " & iLength & "<br>")

'save new image record
Dim cmdInsert As New SqlCommand
Dim insertstring As String
Dim imageid As String

SqlConnect = New SqlConnection(ConnectString)
SqlConnect.Open()

'add company info
insertstring = "INSERT tblImages ( Image_Name, Image_Filename,
Image_Type, Image_FileSize, Image, DateAdded, AddedBy ) VALUES ( @imagename,
@filename, @contenttype, @filesize, @image, @dateadded, @addedby );SELECT
@@Identity" 'using parameters

cmdInsert = New SqlCommand(insertstring, SqlConnect)

With cmdInsert

.Parameters.Add("@imagename", "" & txtimagetitle.Text)
.Parameters.Add("@filename", "" & sFileName)
.Parameters.Add("@contenttype", "" & sContentType)
.Parameters.Add("@filesize", iLength)
.Parameters.Add("@image", bytContent)
.Parameters.Add("@dateadded", Date.Now())
.Parameters.Add("@addedby", Session("contactid"))

End With

imageid = cmdInsert.ExecuteScalar

'close object and connection
SqlConnect.Close()

'add new item to list
ddexistingimages.Items.Add(New ListItem(txtimagetitle.Text,
imageid))

'set label for status
lblstatus.Text = "Image Saved"

Catch ex As Exception
'Handle your database error here

'set label for status
lblstatus.Text = "Error - Please Contact System Administrator."
'close object and connection
SqlConnect.Close()
End Try

"Scott Allen" wrote:
Shawn:

You'll want to check the value of maxRequestLength in web.config or machine.config.
It sounds as if the default value has been overridden but perhaps you'll
need to bump it up higher.

See:
PRB: Cannot Upload Large Files When You Use the HtmlInputFile Server Control
http://support.microsoft.com/default...b;en-us;295626

--
Scott
http://www.OdeToCode.com/blogs/scott/
Hi. I'm letting the users upload images into a sybase 12.5 database.
The problem is that when ContentLength exceeds 131 071 an exception
occur. The e.Message property is empty so it doesn't tell me much. I
know that images much larger than this exist in the database. Any help
is appreciated! Here is my code:

Dim cn As New Connection
Dim oleDbCommand As OleDbCommand
Dim strSqlImage As String
Dim stream As System.IO.Stream = textBoxImage.PostedFile.InputStream
Dim intFileLength As Integer = textBoxImage.PostedFile.ContentLength
Dim byteArray(intFileLength) As Byte
cn.Open()

stream.Read(byteArray, 0, intFileLength)

strSqlImage = "UPDATE TABLE1 SET image = ? WHERE id = " & intID

oleDbCommand = New OleDbCommand(strSqlImage, cn.oleDbConnection)
oleDbCommand.Parameters.Add(New OleDbParameter("@image",
OleDbType.LongVarBinary)).Value = byteArray

oleDbCommand.ExecuteNonQuery()


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Adrian Hill | last post by:
Hi all, I can upload plaintext files to the server fine, but when I try to upload a pdf, it tells me that the file is damaged and could not be repaired. The file is uploaded to the correct place...
1
by: Dean | last post by:
First I've must say Im completly new in php scripting What I need to do is upload, resize pictures with path in database Here is theory of it, and plan of doing it Hope somebody can help me...
4
by: DH | last post by:
I have a "file upload form" that works OK, but I have been unsuccessful in my attempt to also resize the uploaded .JPG (if it is too wide), over-writing the original .JPG, and then create and save...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
5
by: Objectifnet | last post by:
Is there any one who could help with a problem. I have an application that uploads images to a file server with my upload directory set thus:define('ALBUM_IMG_DIR',...
7
tolkienarda
by: tolkienarda | last post by:
hi all I am using a php script to try to upload images to my database. i know i am connecting to my database because the image title is being wirtten to the database. but the image isn't example:...
0
by: ll | last post by:
I'm working with 'pure ASP upload' script which is designed to redirect to an alert/error message, should a file larger than the set limit be attempted to be uploaded. The problem is that, while...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
8
johngault
by: johngault | last post by:
I've been working with this PHP page for several days now and I'm stumped. The page is supposed to allow the user to upload up to six images for their profile. When the user adds an image it (the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.