views:

98

answers:

2

Hey everyone,

I'm wondering how I can hook up an input type=file to send a picture back to a backend servlet that will eventually be stored in a MySQL database as a BLOB? In other words, how can I upload a picture using the input and send that back to the servlet to insert into the database as a BLOB type?

Thanks

A: 

Use commons-fileupload.

Here is a simple tutorial on how to obtain the uploaded item as byte[].

Bozho
+2  A: 

To browse a file for upload, use HTML <input type="file">. To be able to send the selected file in request body, use <form method="post" enctype="multipart/form-data">. To be able to parse the multipart/form-data request, use Apache Commons FileUpload. To get an InputStream of the uploaded file, use FileItem#getInputStream(). To let Java interact with a database, use JDBC API. To store an InputStream in a database, use PreparedStatement#setBinaryStream().

BalusC