Right after I posted this message I came accross another sample code that allowed me pass the error and let me upload the my image.
Here is the code that let me do that. ServletFileUpload upload = *new* ServletFileUpload(); response.setContentType("text/plain"); FileItemIterator iterator = upload.getItemIterator(request); *while* (iterator.hasNext()) { FileItemStream item = iterator.next(); InputStream stream = item.openStream(); *if* (*false* == item.isFormField()) { *int* len; *byte*[] buffer = *new* *byte*[8192]; *while* ((len = stream.read(buffer, 0, buffer.length)) != -1) { //your code build buffer } //your code here to persist to database... use Blob } } I suspect that the error I was getting was due to the use of 'DiskFileItemFactory' On Wed, Oct 21, 2009 at 10:19 PM, hou0175 <kajita...@gmail.com> wrote: > Hi, > > I'm new to GWT and am having problems writing a page to allow users to > upload an image to the server (onto DB using JDO). > > I'm getting the following exception: > > java.security.AccessControlException: access denied > (java.io.FilePermission C:\Users\hou0175\AppData\Local\Temp > \upload__4283d0d0_1247a39ab1c__8000_00000002.tmp write) > > > ----------------------------------------------------------------------------------------------- > The following is the code on my client side that I grabbed from the > web: > > // Create a TextBox, giving it a > name so that it will be submitted. > final TextBox tb = new TextBox(); > tb.setName("textBoxFormElement"); > panel.add(tb); > > // Create a ListBox, giving it a name and some values to > be > associated with > // its options. > ListBox lb = new ListBox(); > lb.setName("listBoxFormElement"); > lb.addItem("foo", "fooValue"); > lb.addItem("bar", "barValue"); > lb.addItem("baz", "bazValue"); > panel.add(lb); > > // Create a FileUpload widget. > FileUpload upload = new FileUpload(); > upload.setName("uploadFormElement"); > panel.add(upload); > > // Add a 'submit' button. > panel.add(new Button("Submit", new ClickListener() { > public void onClick(Widget sender) { > form.submit(); > } > })); > > // Add an event handler to the form. > form.addFormHandler(new FormHandler() { > public void onSubmit(FormSubmitEvent event) { > // This event is fired just before the form is > submitted. We > can take > // this opportunity to perform validation. > if (tb.getText().length() == 0) { > Window.alert("The text box must not be empty"); > event.setCancelled(true); > } > } > > public void onSubmitComplete(FormSubmitCompleteEvent > event) { > // When the form submission is successfully > completed, this > event is > // fired. Assuming the service returned a response > of type > text/html, > // we can get the result text here (see the > FormPanel > documentation for > // further explanation). > Window.alert(event.getResults()); > } > }); > > //} > > > > m_MainDisplayPanel.add(form); > RootPanel.get("blogPanel").add(decoratorPanel); > > > --------------------------------------------------------- > The following is the code on my server side (also from some samples > online): > > boolean isMultipart = ServletFileUpload.isMultipartContent(request); > List items = null; > String text ="not loaded!"; > > if ( isMultipart ) { > // Create a factory for disk-based file items > FileItemFactory factory = new DiskFileItemFactory(); > > // Create a new file upload handler > ServletFileUpload upload = new ServletFileUpload(factory); > > // Parse the request > try { > items = upload.parseRequest(request); > <===========================I get the exception here > } catch (Exception e) { > text = e.getStackTrace().toString(); > } > } > > > > > I'm getting the exception on "items = upload.parseRequest(request); " > > > I'm running GWT in Hosted Mode. > > I'm not sure if i can do this in Hosted Mode. If not, how can I test > my code before I deploy it? > > I must be doing something trivial wrong. I'd appreciate if someone > could point me to the right direction. > > I thank you in advance for your help. > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en -~----------~----~----~----~------~----~------~--~---