Uploading Multiple File Formats To A Server Using Jsp And Store The Path In Database
Solution 1:
I strongly advice you use one of the existing modules people have built for multipart file upload handling. Commons Fileupload is on of the more popular, I suggest you look into it (usage example here).
Your code is pretty messy and you are mixing working with byte arrays and Strings in a way that is sure to create errors. This:
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
...
fileOut.write(dataBytes, startPos, (endPos - startPos));
is particularly hairy. Anyway, if you insist on doing it yourself, you should clean up your code, don't mix working with Strings and byte arrays (remember, one character in a string is not necessarily just one byte). I don't recommend it though, unless this is a learning experience for you. In which case I would spend some time to try and find some example code on the internet for multipart form handling.
Solution 2:
Use mediumblob(upto 16mb upload)
or longblob(upto 1 gb or 4 gb)
in mysql.
and add below the [mysqld]
line in my.ini
- if you use mediumblob in mysql:
max_allowed_packet=16M
- if you use
largeblob
in mysql:max_allowed_packet=1024M
Post a Comment for "Uploading Multiple File Formats To A Server Using Jsp And Store The Path In Database"