Hellos balachandra ! :D

I create this solution and it  works fine:

Cliente side:

final FormPanel form = new FormPanel();

final FileUpload upload = new FileUpload();

public static  String UPLOAD_RESULT = "";

public static String EVENT_NAME = "";

private boolean isIMG = true;


 public FileUploadPadroes(){

form.setEncoding(FormPanel.ENCODING_MULTIPART);

form.setMethod(FormPanel.METHOD_POST);


 HorizontalPanel holder = new HorizontalPanel();


  upload.setName("upload");

 holder.add(upload);

  upload.addChangeHandler(new ChangeHandler() {

 @Override

public void onChange(ChangeEvent event) {


 form.setAction("/padroes/UploadService?isIMG="+isIMG()+"&eventName="+
EVENT_NAME);


 if(upload.getFilename()==null || upload.getFilename().length()<1){

// PageBusAdapter.publishDoCreateEventUpload("No valid file attached.");

}else{

form.submit();

}

 }

});

 form.add(holder);

  }


 public FormPanel getForm() {

 return form;

}

 public FileUpload getUpload() {

return upload;

}


 public boolean isIMG() {

return isIMG;

}


 public void setIMG(boolean isIMG) {

this.isIMG = isIMG;

}

On server side :

protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {


// ServletFileUpload uploadHandler = new ServletFileUpload();

boolean isIMG = Boolean.parseBoolean(request.getParameter("isIMG"));

 // Create a factory for disk-based file items

DiskFileItemFactory factory = new DiskFileItemFactory();


 // Create a new file upload handler

ServletFileUpload upload = new ServletFileUpload(factory);


 if(isIMG){

// Set factory constraints

factory.setSizeThreshold(1000000);//"resources/upload"

// Set overall request size constraint

upload.setSizeMax(1000000);

}else {

// Set factory constraints

factory.setSizeThreshold(10000000);//"resources/upload"

// Set overall request size constraint

upload.setSizeMax(10000000);

}



 try {

 /*

 * Parse the request

 */

String eventName = request.getParameter("eventName");

 List<FileItem> lUploadingFiles = upload.parseRequest(request);

for (FileItem item : lUploadingFiles) {


 processUpload(item,isIMG,eventName);

 }


 }catch(FileUploadException ex) {

FileUploadPadroes.UPLOAD_RESULT = "The file size is to big," +

" must be less than 1MB.";

log("Error encountered while parsing the request",ex);

} catch(Exception ex) {

log("Error encountered while uploading file",ex);

}

}


 private void processUpload(FileItem uploadItem,boolean isIMG,String
eventName)

{

 File uploadedFile = null;

 String uploadFileName = uploadItem.getName();



if(isIMG)

uploadedFile = new File("padroes/resources/event/"+ eventName +"/images/" +
uploadFileName);

else

uploadedFile = new File("padroes/resources/event/"+ eventName +"/videos/" +
uploadFileName);

   /**

    * handling file uploads

    */

      try

  {

uploadItem.write(uploadedFile);


 } catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

 }



On Wed, Jun 16, 2010 at 8:54 AM, balachandra maddina
<chandu2...@gmail.com>wrote:

> Hi There,
>
>   Im trying a file upload using the below code but on my server side no
> file items are available but without changing the server code if i try using
> a plain html with a form then the server was able to see file items. please
> let me know if im missing anything here.
>
> GWT code:
> -----------------
>
>>   uploadForm = new FormPanel();
>>
>>       uploadForm.reset();
>>
>>       uploadForm.setAction("../upload");
>>
>>       uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
>>
>>       uploadForm.setMethod(FormPanel.METHOD_POST);
>>
>>
>>>       FileUpload upload = new FileUpload();
>>
>>       uploadForm.add(upload);
>>
>>       uploadPanel.add(uploadForm);
>>
>>
> Server side code:
> -------------------------
>
>> String contentType = request.getContentType();
>
>       if (!ServletFileUpload.isMultipartContent(request)) {
>
>          return super.onSubmit(request, response, command, errors);
>
>       }
>
>       FileItemFactory factory = new DiskFileItemFactory();
>
>       ServletFileUpload upload = new ServletFileUpload(factory);
>
>       try {
>
>          List<FileItem> fileItems = upload.parseRequest(request);
>
>          if (null != fileItems && !fileItems.isEmpty()) {
>
>
>
> Your help is very much appreciated.
>
> Thank you,
> bala.
>
> --
> 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-tool...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>

-- 
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-tool...@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.

Reply via email to