h:大于1Mb的inputFile无法上传

时间:2016-07-26 13:30:56

标签: jsf file-upload

我有这个简单的文件上传表单。

            

        <h:outputLabel for="scannedImage" value="Upload scanned image: " />
        <h:inputFile id="scannedImage" value="#{fileUploadBean.file}" required="true"
                     requiredMessage="Please select a scanned file" />
        <h:message for="scannedImage" style="color: red;" />
        <h:commandButton value="Upload" action="#{fileUploadBean.upload()}"/>
    </h:form>

如果filesize小于1Mb,我的fileupload可以正常工作。但是如果filesize大于1Mb,它会跳过上传文件。也没有错误。如何使这项工作,以便我可以上传大于1Mb的文件大小。以下是我的上传和验证方法的一部分。

public String upload() throws IOException, GeneralSecurityException, DecoderException {

InputStream inputStream = file.getInputStream();
        String filename = getFilename(file);

        return "index.xhtml";
    }

public void validateForm (ComponentSystemEvent event) throws IOException{
FacesContext fc = FacesContext.getCurrentInstance();
        UIComponent components = event.getComponent();
        UIInput uiInputImage = (UIInput) components
                .findComponent("scannedImage");
        Part file;
        file = (Part)uiInputImage.getLocalValue();
int maxFileSize = 5*1024*1024;
            if (!(file.getSize()<maxFileSize)){
                FacesMessage msg = new FacesMessage(
                        "File size must be less than 2Mb");
                msg.setSeverity(FacesMessage.SEVERITY_ERROR);
                fc.addMessage(scannedImageId, msg);
                fc.renderResponse();
            }
}

0 个答案:

没有答案