File uploading problem
Take file as part from form.
Then create a folder in target. Target is a folder which will be run during execution. Upload photo there and name in the data base.
// Uploading picture
try {
String path = request.getRealPath("image") + File.separatorChar + "products" + File.separatorChar + pPhoto.getSubmittedFileName();
System.out.println(path);
FileOutputStream fos = new FileOutputStream(path);
InputStream fis = pPhoto.getInputStream();
// Reading data
byte[] data = new byte[fis.available()];
fis.read(data); // This will place the file data in byte[] data
// Writing the data
fos.write(data);
fos.close();
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
Comments
Post a Comment