lundi 18 mai 2015

if statement does not seem to ever evaluate false

Goal: User uploads an image, a validator checks to make sure it is an image file the user uploaded, returns message if it is not an image, doesn't if it is.

Issue: When Upload button is clicked, regardless of whether the uploaded file is an image or not an image, the validator message is always returned.

Area of Focus: In the Validator class, the line System.out.println(partValueContentType); has written the content type to the console, ex. image/jpeg, but when it is tested in the if statement it does not seem to evaluate the content type at all.

        String partValueContentType = part.getContentType();
        System.out.println(partValueContentType);

        if (!partValueContentType.equals("image/jpeg")
                || !partValueContentType.equals("image/jpg")
                || !partValueContentType.equals("image/gif")
                || !partValueContentType.equals("image/png"))
        {
            FacesMessage msg = new FacesMessage("File is not an image.",
                    "Acceptable image types (jpeg, jpg, gif, png)");
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
            throw new ValidatorException(msg);
        }

How is this caused and how can I solve it?

Aucun commentaire:

Enregistrer un commentaire