Skip to content

Error: Given file is neither JPEG nor TIFF. #145

@bowencool

Description

@bowencool

Codes:

//Node.js v20.9.0, v18.18.2
import { readFile } from "node:fs/promises";
import { load } from "piexifjs";

// ...
  if (fileName.match(/\.(jpg|jpeg|png)$/i)) {
    console.log(RegExp.$1);
    const dataURL = await readFile(filePath, { encoding: "base64" });
    const exifObj = load(`data:image/${RegExp.$1};base64,${dataURL}`);
  }
// ... 

Outputs:

              throw new Error("Given file is neither JPEG nor TIFF.");
                    ^

Error: Given file is neither JPEG nor TIFF.
    at ExifReader (/xxx/node_modules/.pnpm/piexifjs@2.0.0-beta.9/node_modules/piexifjs/dist/piexif.js:2123:21)

Image:

639__836EF234

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions