I am using JSP form to upload and Servlet to store a large-sized file in a MySQL database. and because i am new to Java in general, i need a really urgent help.
I tried to store the file in a String value but i got error that string index is out of boundary.
I have the database table Files which has (varchar File_Name, Blob File_data, Varchar File_Date) .
And i need to store the uploaded file inside the
I had this code in servlet:
** BTW : i have no idea why “DiskFileUpload, parseRequest ” have strikethrough line ?
try {
InputStream uploadedFile = null;
<strike>DiskFileUpload</strike> fu = new </strike>DiskFileUpload</strike>();
// If file size exceeds, a FileUploadException will be thrown
fu.setSizeMax(10000000);
List fileItems = fu.<strike>parseRequest</strike>(request);
Iterator itr = fileItems.iterator();
while (itr.hasNext()) {
FileItem fi = (FileItem) itr.next();
//Check if not form field so as to only handle the file inputs
//else condition handles the submit button input
if (!fi.isFormField()) { // If the form fiel is a file
uploadedFile = fi.getInputStream();
}
What type of data should I convert uploadFile cvariable to be able to store it in a Blob attribute ?
Strike through means API is deprecated and those classes/methods may not work as expected.
Storing file to database, you need to store the content as bytes in blob filed. See this discussion. Even though it is related to some error, OP posted code on how to do this.