开发者

File Upload in fire fox

开发者 https://www.devze.com 2023-02-14 14:14 出处:网络
Iam not able to upload files in FireFox and safari but iam able to do it successfully in explorer. When i tried to debug i found out that in case of IE the upload browser is giving the entire file as

Iam not able to upload files in FireFox and safari but iam able to do it successfully in explorer. When i tried to debug i found out that in case of IE the upload browser is giving the entire file as eg C:\Documents and Settings\jjayashree\My Documents\price.csv but where as in FF and safari the upload widget is just giving the file name with no extension. previously code was like this if (file开发者_如何学运维Name.contains("\")) { index = fileName.lastIndexOf("\"); }

    if (this.fileName != null && this.fileName.trim().length() > 0 && index >= 0) {
        this.fileName = this.fileName.substring(index + 1, this.fileName.length());
    int dotPosition = fileName.lastIndexOf('.');
        String extension = fileName.substring(dotPosition + 1, fileName.length());
        try {

            if (profileType.equalsIgnoreCase("sampleProfile")) {
                if (extension.equalsIgnoreCase("csv")) {
                    //fileNameTextBox.setText(this.fileName);
                    this.form.submit();
                } else {
                    new CustomDialogBox(Nexus.INFO_MESSAGE, MessageConstants.SPECIFY_FILE_NAME_MSG).show();
                }
            }
    } catch (Exception e) {
           Window.alert("SPECIFY_VALID_FILE_NAME_MSG");
        }
    } else {
           Window.alert("SPECIFY_A_FILE_MSG");
    }

i changed it as if (this.fileName != null && this.fileName.trim().length() > 0) { this.fileName = this.fileName.substring(this.fileName.lastIndexOf("\") + 1, this.fileName.length()); }

i found it working but when the same is deployed in linux iam getting an error

I also hav a doubt becos in the doPost of servlet iam using fileName.replace("\", "/");

is this the problem. . How wil mozilla encounter this fileName.replace() wil it just see and find nothing can be replced and go or wil it throw any kind of Exception


Maybe try gwtupload? It simplifies file loading to one function call, and handles all the backend for you. It's a little complicated to get working but there's a tutorial on the site on how to do it.

http://code.google.com/p/gwtupload/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号