Gwt文件上传服务器端的MIME类型

时间:2013-07-16 06:37:36

标签: java gwt

我在我的代码中使用GWt fileuploader。 在服务器端,我有getContentType来获取MIME类型。 当我在本地运行并上传.PDF文件时,它将ContentType返回为“application / pdf”。 但是当我在应用程序服务器上部署代码时,它将ContentType作为“application / octet-stream”返回给我。

我需要设置MIME类型。这里我将ContentType设置为MIMEtype。 当我获得不同的ContentType时,“application / octet-stream”的调用失败。

以下是代码:

               Iterator<FileItem> iter = items.iterator(); 
        byte[] file ;       

        byte[] apacheBytes;
        System.out.println("before while" );
        while (iter.hasNext()) {                

            FileItem item = (FileItem) iter.next();   

                fileName = item.getName(); 
                System.out.println("fileName is : " + fileName);  
                typeMime = item.getContentType();      
                System.out.println("typeMime is : " + typeMime); 
                int sizeInBytes = (int) item.getSize();  
                System.out.println("Size in bytes is : " + sizeInBytes); 
                file = item.get();                                      
                apacheBytes =  org.apache.commons.codec.binary.Base64.encodeBase64(file);
                System.out.println("The ApacheBytes="+apacheBytes);



            }  

客户端代码:

           FlowPanel mainPanel=new FlowPanel();
    form = new FormPanel(); 

    form.setMethod(FormPanel.METHOD_POST);    

    //The HTTP request is encoded in multipart format.      
    form.setEncoding(FormPanel.ENCODING_MULTIPART); 
    //  multipart MIME encoding     

    form.setAction("/FileUploadServlet");
    form.setWidget(mainPanel);
    uploadButton=new NFUMButton("Browse");
    addButton=new Button("Add");
    FileUpload fileUpload = new FileUpload();
    fileUpload.setName("uploader");



    FlowPanel errPanel=new FlowPanel();
    errPanel.setStyleName("error_message");
    FlowPanel errIconPanel=new FlowPanel();
    Element span=DOM.createElement("span");
    span.setInnerText("Document size should not excedd 100mb");
    errIconPanel.getElement().insertFirst(span);

    errIconPanel.setStyleName("error_icon");
    errPanel.add(errIconPanel);     
    mainPanel.add(errPanel);

    FlowPanel fileuploadPanel=new FlowPanel();
    fileuploadPanel.setStyleName("fileupload");


    Element span1=DOM.createElement("span");
    //span.setInnerText("(Chetan Document size should not excedd 100mb)");


//  fileuploadPanel.getElement().insertAfter(span1, span);
    FlowPanel buttonPanel=new FlowPanel();

    buttonPanel.setStyleName("button_body");

    addButton.setStyleName("add");
    buttonPanel.add(addButton);

    fileuploadPanel.add(fileUpload);
    fileuploadPanel.add(buttonPanel);

    mainPanel.add(fileuploadPanel);     
    //this.initWidget(mainPanel);
    this.initWidget(form);                         

0 个答案:

没有答案