Silverstripe 3.1.5 - Error loading SyntaxError: Unexpected token <

I need to download .svg files. For this, I added 'svg' to my config.yml, to the allowed extensions in the upload a field and .htacces in assets /. Also all my resource directories have CHMOD 777.

The file is downloading but not connecting. Instead, I am getting this error in the SyntaxError upload field: Unexpected token <

File: 
  allowed_extensions:
    - svg
Image: 
  allowed_extensions:
    - svg



$logo->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif', 'svg'));


Deny from all
<FilesMatch "\.(?i:html|htm|xhtml|js|css|bmp|png|gif|jpg|jpeg|ico|pcx|tif|tiff|au|mid|midi|mpa|mp3|ogg|m4a|ra|wma|wav|cda|avi|mpg|mpeg|asf|wmv|m4v|mov|mkv|mp4|ogv|webm|swf|flv|ram|rm|doc|docx|txt|rtf|xls|xlsx|pages|ppt|pptx|pps|csv|cab|arj|tar|zip|zipx|sit|sitx|gz|tgz|bz2|ace|arc|pkg|dmg|hqx|jar|xml|pdf|gpx|kml|svg)$">
    Allow from all
</FilesMatch>

      

+3


source share


3 answers


Silverstripe (3.1) will not let you save the svg file as an image data type. It might be related to the PHP GD library (I'm not sure) that the Silverstripe class uses Image

.

You can save the svg file as a datatype instead File

.

To do this, you need to add the svg file to File

allowed_extensions

your yml config file (as you posted in your questions):

File: 
  allowed_extensions:
    - svg

      



In your Page or DataObject class, add a relationship File

and set UploadField

:

private static $has_one = array(
    'SVGFile' => 'File'
);

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.SVG', UploadField::create('SVGFile', 'SVG File'));

    return $fields;
}

      

In the page template, you can use the file url to download the svg as you like.

+6


source


Here's a module where SVG works like images in SilverStripe: https://github.com/micschk/silverstripe-svg-images/



See the README for general pointers on how to customize the SVG image if you don't want to require a module.

+1


source


The issue "SyntaxError: Unexpected token <" is caused by an error being returned via HTML instead of a data stream in my experience. So I would look at the content of the response on the network tab and expect to see the stack trace with an error.

+1


source







All Articles