BookStackApp/BookStack · error · Error

Not an image file

Error message

Not an image file

What it means

Guard in uploadImageFile rejecting a File that is null or whose MIME type does not start with 'image', meaning a non-image (or unknown-type) file was passed to the image upload path. Input at fault: the dropped/pasted file with a non-image type.

Source

Thrown at resources/js/wysiwyg/utils/images.ts:34

    }, 'gallery');
}

export function $createLinkedImageNodeFromImageData(image: EditorImageData): LinkNode {
    const url = image.thumbs?.display || image.url;
    const linkNode = $createLinkNode(url, {target: '_blank'});
    const imageNode = $createImageNode(url, {
        alt: image.name
    });
    linkNode.append(imageNode);
    return linkNode;
}

/**
 * Upload an image file to the server
 */
export async function uploadImageFile(file: File, pageId: string): Promise<EditorImageData> {
    if (file === null || file.type.indexOf('image') !== 0) {
        throw new Error('Not an image file');
    }

    const remoteFilename = file.name || `image-${Date.now()}.png`;
    const formData = new FormData();
    formData.append('file', file, remoteFilename);
    formData.append('uploaded_to', pageId);

    const resp = await window.$http.post('/images/gallery', formData);
    return resp.data as EditorImageData;
}

View on GitHub (pinned to 18f8469a1c)

Solutions

  1. Only pass files with an image/* MIME type to uploadImageFile
  2. Show the user a file-type error before invoking upload
  3. Check browser-provided file.type; some files may report empty type and need extension fallback
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at resources/js/wysiwyg/utils/images.ts:34 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BookStackApp/BookStack@18f8469a1c (2026-09-02). Data as JSON: /api/errors/efc872efc2a71b06. Report an issue: GitHub.