Cannot attach SVG from draw.io

AI-generated summary

A user, toksvaeth, reported an issue with attaching SVG files generated from draw.io to Discourse topics. The error message received was “Sorry, but we couldn’t determine the size of the image. Maybe your image is corrupted?” The issue was identified as draw.io’s SVG export including a <!DOCTYPE> declaration, which is not supported by the fastimage library used by Discourse. zogstrip created a pull request and temporary gem to address the issue, which was later committed to the Discourse repository.

Hello,

I use draw.io to render technical diagrams. It is often of benefit to attach these to discussion topics to further a conversation or demonstrate an idea. Draw.io has the ability to export in SVG format, which is my preference when working with other discussion software.

When attempting to attach an SVG image generated through draw.io to a Discourse topic, I am unable to do so. Instead, I receive this error:

Sorry, but we couldn’t determine the size of the image. Maybe your image is corrupted?

I am currently uncertain if there is something special about the SVG format that draw.io uses, or if Discourse is having trouble dealing with SVG files.

Steps to reproduce

A sample SVG file is available for your use. Alternatively, follow the steps below:

  1. Head to draw.io and start a new diagram.
  2. Add any arbitrary shape (just one is fine) to the diagram.
  3. Head to File > Export As > SVG…
  4. Accept the defaults and hit Export.
  5. Create a new Discourse topic.
  6. Attempt to upload your SVG file.

Expected Result: SVG file is attached to the topic and (hopefully) rendered for users.

Actual Result: Unable to attach file. Error message received as follows:

Sorry, but we couldn’t determine the size of the image. Maybe your image is corrupted?

7개의 좋아요

Best Contribute > Bug report I’ve seen in a while :+1:

Turns out, draw.io exports SVGs with a <!DOCTYPE> which isn’t supported by the library we use to determine the image’s dimension.

Made a PR and pushed a temp gem so we can use it :wink:

9개의 좋아요