Docly Developers
Knowledge base Bug Workaround available

The site router answers 500 on attachment and scaled-image URLs

In shortOn a publication with a site router (router.script in site.json), requests for an embedded file or a scaled image - <document>/<embedded-id>/<name> and <document>/<embedded-id>/<W>x<H>x<M>/<name> - fail with 500 "Specified path is empty" before the router code runs. Until this is fixed, serve such files through an API script that checks access and returns the bytes.
Applies to Site routerImagesUploaded files
  1. What you'll see

    You protect a site with a router, as described in Use the site router for your own sign-in and API tokens or in the two-layer model, and link files and thumbnails with linkFile and linkImage. Pages and API calls work. Every embedded file and every scaled image returns 500.

  2. What's actually happening

    The site console shows The router #/Services/Router.js failed … Specified path is empty for these URLs. The error happens before your router function runs. Measured 2026-11-28 with a router reduced to return route.next() and no imports: the attachment URL and a linkImage URL (…/160x200x1/brochure.webp) both returned 500. The same URLs return 200 on a publication without a router. The KB article Images that should be scaled cannot live under the # folder describes these URLs as passing through the router. With this bug they do not.

  3. What to do

    Workaround until the platform is fixed: give the files an API endpoint that runs the same access rule as the router and returns the bytes. This version is in production use (measured 2026-11-28):

    // #/API/Thumbnail.js - GET ?path=<file path>
    import { requireUser, canSeePath } from "#/Libs/Access.js";
    
    export default () => {
        const user = requireUser();
        const path = ("" + (query.path || "")).trim();
        if (!path || path.indexOf("..") >= 0 || path.replace(/^\/+/, "").startsWith("#")) throw { error: "Invalid file." };
        const f = docly.getFile(path);
        if (!f || !f.File) throw { error: "File not found." };
        // check access on the folder the document actually lives in, not on what the caller sent
        if (!canSeePath(user, f.folderpath + "/" + f.filename)) { docly.denyAccess(); throw { error: "No access." }; }
        const data = docly.getEmbeddedFile(f.filepath, f.File);
        const image = docly.scaleImage(data, 160, 200, { mode: "ScaleToFit", format: "webp" });
        return docly.downloadBytes(image, "preview.webp", true);
    };

    scaleImage also renders the first page of a PDF. downloadBytes currently drops headers set with setHeader, so put a version in the URL (?v=<LastModified>) instead of relying on browser caching (see downloadBytes ignores headers set with setHeader). Remove the workaround when this entry is marked Resolved.

Last reviewed 28 Nov 2026