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.

CommentFileSizeAuthor
#10 3458204-10.patch6.78 KBram4nd
#2 3458204-1.patch626 bytesisalmanhaider

Comments

isalmanhaider created an issue. See original summary.

isalmanhaider’s picture

StatusFileSize
new626 bytes

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.

isalmanhaider’s picture

Issue tags: +core, +svg_image
isalmanhaider’s picture

Project: Svg Image » Drupal core
Version: 7.x-1.2 » 7.x-dev
Component: Code » field system
Priority: Normal » Major
Status: Active » Needs work
isalmanhaider’s picture

Component: field system » file system
poker10’s picture

Project: Drupal core » Svg Image
Version: 7.x-dev » 7.x-1.x-dev
Component: file system » Code

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 #2345695: Users are able to upload 0-byte images 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.

a_z_official’s picture

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?

a_z_official’s picture

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!

mr.pomelov’s picture

Solution #8 works for me (D 7.101)

ram4nd’s picture

Issue tags: -core, -svg_image
StatusFileSize
new6.78 KB