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
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 anInputStreamof the uploaded file, useFileItem#getInputStream(). To let Java interact with a database, use JDBC API. To store anInputStreamin a database, usePreparedStatement#setBinaryStream().