Can you give an example of how a servlet might process the poster plugin’s doPost() method to write files to a directory on the server?
Thanks,
Sean
Can you give an example of how a servlet might process the poster plugin’s doPost() method to write files to a directory on the server?
Thanks,
Sean
pseudo/sample code
import org.apache.commons.fileupload.DefaultFileItemFactory;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUpload;
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
String ct = request.getContentType();
if (ct != null && ct.startsWith("multipart/form-data;")) //$NON-NLS-1$
{
File file = null;
String fileName = null;
FileUpload fileUpload = new FileUpload(new DefaultFileItemFactory());
try
{
List list = fileUpload.parseRequest(request);
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
FileItem fileItem = (FileItem) iterator.next();
if (fileItem.isFormField())
{
if ("file".equals(fileItem.getFieldName())) //$NON-NLS-1$
{
file = File.createTempFile("import", ".servoy"); //$NON-NLS-1$ //$NON-NLS-2$
fileItem.write(file);
fileName = fileItem.getName();
}
}
}
}
catch(Exception ex)
{
}
if (file != null)
{
//process file
}
}
}