The specified file stats.svg could not be uploaded. The image file is invalid or the image type is not allowed. Allowed types: Only JPEG, PNG and GIF images are allowed.

Created on 1 July 2024, 5 months ago

I'm experiencing the same error on Drupal 7.101 with svg_image 7.x-1.2 while the allowed types is set to `jpg svg`

The specified file stats.svg could not be uploaded. The image file is invalid or the image type is not allowed. Allowed types: Only JPEG, PNG and GIF images are allowed.

πŸ› Bug report
Status

Active

Version

1.2

Component
File systemΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡΅πŸ‡°Pakistan isalmanhaider

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @isalmanhaider
  • πŸ‡΅πŸ‡°Pakistan isalmanhaider

    It seems the issue originated from the update described in Drupal 7.99 β†’ , as detailed in this change record β†’ .

    The problem can be resolved by modifying the validation condition to include $file->filemime != 'image/svg+xml', allowing SVG files to bypass the strict image checks that were causing errors.

  • Status changed to Needs work 5 months ago
  • πŸ‡ΈπŸ‡°Slovakia poker10

    Thanks for reporting this. I think this is something which needs to be changed in the svg_image module in the svg_image_field_widget_form_alter() function. Currently the module is altering the #upload_validators (see here).

    In πŸ› Users are able to upload 0-byte images Fixed a new upload validator was added (see here):

    +    $elements[$delta]['#upload_validators']['file_validate_is_image'] = array();
    

    The module can remove the new validator to work as before.

    Or you can use hook_field_widget_form_alter to remove it in the custom module as well.

  • πŸ‡΅πŸ‡°Pakistan a_z_official

    I'm experiencing the same issue. How can I resolve it?
    When attempting to upload an SVG file through the node creation form, I receive:
    "The specified file 'default.svg' could not be uploaded. The image file is invalid or the image type is not allowed."
    Additionally, when trying to set an SVG as the default image, I get:
    "'default.svg' could not be uploaded. Only files with the following extensions are allowed: jpg, jpeg, gif, png, txt, doc, xls, pdf, ppt, pps, odt, ods, odp."
    Can someone please assist me in resolving this issue?

  • πŸ‡΅πŸ‡°Pakistan a_z_official

    In my previous comment, I shared that I was facing the same problem when trying to upload SVG files:
    β€œThe specified file 'default.svg' could not be uploaded. The image file is invalid or the image type is not allowed.”
    I also ran into an issue when setting an SVG as the default image:
    β€œ'default.svg' could not be uploaded. Only files with the following extensions are allowed: jpg, jpeg, gif, png, etc.”
    After digging into the issue, I decided to create a custom Drupal 7 module to fix it. This module, SVG Upload Fix, tweaks the image upload process to skip the validation for SVG files, allowing you to upload SVGs and set them as default images without any errors.
    You can check out the module on GitHub: SVG Upload Fix. I hope this helps others who might be dealing with the same issue!

Production build 0.71.5 2024