pqina / filepond

🌊 A flexible and fun JavaScript file upload library
https://pqina.nl/filepond
MIT License
15.15k stars 825 forks source link

[Bug] svg image previews are shown at `imagePreviewMaxHeight` instead of using svg dimensions #846

Open mattwbarry opened 2 years ago

mattwbarry commented 2 years ago

Is there an existing issue for this?

Have you updated FilePond and its plugins?

Describe the bug

When displaying a svg file either after adding the file in the browser or loading an existing image from the server, the height of the preview is set to imagePreviewMaxHeight instead of using the height defined in the svg file.

For example, a .svg file containing height="40px" width="40px" gets stretched to the default imagePreviewMaxHeight value of 256px.

Screen Shot 2022-06-10 at 10 56 12 AM

Reproduction

Using filepond-plugin-image-preview, add a .svg file with height defined in the file.

React component using react-filepond:

export const FileInput = (props) => {
  const { defaultValue } = props;
  const initialFiles = defaultValue
    ? [
        {
          source: defaultValue,
          options: {
            type: 'local',
          },
        },
      ]
    : [];
  const [files, setFiles] = useState(initialFiles);

  return (
    <>
      <FilePond
        files={files}
        onupdatefiles={setFiles}
        server={{
          load: (url, load) => {
            fetch(url)
              .then((res) => {
                return res.blob();
              })
              .then(load);
          },
        }}
        instantUpload={false}
        storeAsFile={true}
      />
    </>
  );
};

Environment

- Device: Macbook Pro 2021
- OS: OSX 12
- Browser: Firefox 101, Chrome 102
rikschennink commented 2 years ago

Can you try with px

<svg height="40" width="40">

mattwbarry commented 2 years ago

Same result