🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Error importing SVG file with invalid metadata in Sanity CLI

16 replies
Last updated: Jul 1, 2021
Hey all. I tried exporting a dataset and reimporting it using sanity/cli and get the following error message during import:
o: Failed to upload image @ file:///private/var/folders/yy/n3wpcs896hg369pyrwjmtd8w0000gn/T/ef684c991e2f22d04628e302b9e7225d/sanity-import/production-export-2021-06-29t06-33-57-244z/images/2f2fe1cbd0563b3ce3ea79fcdf1549ed244b3993-120x40.svg:
Bad Request - Invalid image, could not read metadata
    at onResponse (~/.nvm/versions/node/v14.16.0/lib/node_modules/@sanity/cli/bin/sanity-cli.js:4206:533)
    at ~/.nvm/versions/node/v14.16.0/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2736:279
    at ~/.nvm/versions/node/v14.16.0/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2724:918
    at ~/.nvm/versions/node/v14.16.0/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2724:1026
    at E (~/.nvm/versions/node/v14.16.0/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2772:1332)
    at ~/.nvm/versions/node/v14.16.0/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2772:2845
    at s.<anonymous> (~/.nvm/versions/node/v14.16.0/lib/node_modules/@sanity/cli/bin/sanity-cli.js:1320:100)
    at A (~/.nvm/versions/node/v14.16.0/lib/node_modules/@sanity/cli/bin/sanity-cli.js:1338:6029)
The file in question is an SVG file and (I assume) the importer is trying to read JPEG/PNG metadata. Maybe this has something to do with:
https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1624181782323300

This used to work without sanity/cli complaining about image metadata. Is there a solution to this? Thank you in advance.
Jun 29, 2021, 6:43 AM
I just tried the same procedure with 2.10.0 and 2.7.4 of the sanity/cli package and it seems like the error is not sanity/cli dependent but API specific, as the error message stays the same.
Jun 29, 2021, 7:12 AM
i see you’re uploading an svg but does this error for other common types like jpg or png?
Jun 29, 2021, 8:09 AM
Could you DM me the SVG in question?
Jun 29, 2021, 8:13 AM
user G
The error happens at 4% of "uploading assets", so I assume other files go through
Jun 29, 2021, 8:16 AM
Let me have a look at the file
Jun 29, 2021, 8:17 AM
Posted the SVG to
user Z
- didn't see anything wrong with the file, it opens just fine in OSX/preview. Out of all the attempts that stopped at a varying degree of completeness of the "uploading assets" stage, it always breaks with the same file
Jun 29, 2021, 8:23 AM
WebStorm complains about an illegal attribute on an xml property but that shouldn't affect imports, unless there is advanced magic happening on your side like SVG syntax verification?
Jun 29, 2021, 8:35 AM
There is some SVG sanitization which I believe is causing this. I'm trying to figure out if there's attributes that are considered "dangerous" in here somehow.
Jun 29, 2021, 8:45 AM
OK. "data-name" is considered illegal by WebStorm's parser
Jun 29, 2021, 8:53 AM
Yeah. I think it's the
<
/
>
in there that is throwing of our image processor
Jun 29, 2021, 8:57 AM
an empty closing tag like
</>
? I can't see one
Jun 29, 2021, 9:08 AM
or this:
<g
*id*="_Group_" *data-name*="<Group>"*>*
Jun 29, 2021, 9:09 AM
To be honest, I just grabbed that SVG and uploaded it 2 years ago when there was no sanitiser in place I think, hehe
Jun 29, 2021, 9:09 AM
The latter. And yeah, the sanitizer is a new addition to the pipeline, to prevent XSS and such. We're still trying to balance it in terms of how eager it is 😉
Jun 29, 2021, 9:38 AM
user B
We've deployed some changes that should make this go through now - can you verify?
Jun 29, 2021, 2:24 PM
user Z
Seems to do the trick. Thanks for looking into this!
Jul 1, 2021, 5:50 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?