Hi all,
I am currently working on an gwt application where the client needs to
upload some files on the server so they can undergo some further
processing.
I found the Servlet shown below in some Tutorial that, invoked by the
client, should allow me to upload a file to the server. Interestingly,
this works for small files (text and binary) a far as they are not
larger than something around 15 kb.
Otherwise, I get an error looking like this: "access denied
(java.io.FilePermission /var/folders/iw/iwDgjwOcEVqjzDb6t18ytnj1v9w/-
Tmp-/upload_78b21457_132f972f394__8000_00000010.tmp write)"
Help would be much apreciated! Thanks in advance!
Best Regards,
Uli
PS: And here comes the code:
public class FileUploadServlet extends HttpServlet implements Servlet
{
private static final long serialVersionUID = 8305367618713715640L;
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/plain");
FileItem uploadItem = getFileItem(request);
if (uploadItem == null) {
response.getWriter().write("NO-SCRIPT-DATA");
return;
}
byte[] fileContents = uploadItem.get();
//TODO: add code to process file contents here. We will just
printit.
System.out.println(new String(fileContents));
response.getWriter().write(new String(fileContents));
}
private FileItem getFileItem(HttpServletRequest request) {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
System.out.println(request);
List items = upload.parseRequest(request);
System.out.println("FILE READ ###############################");
Iterator it = items.iterator();
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
if (!item.isFormField()
&& "uploadFormElement".equals(item.getFieldName())) {
return item;
}
}
} catch (FileUploadException e) {
return null;
}
return null;
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.