Skip to content

[Bug]: Previews of document like DOCX can't be generated when flysystem (S3 buckets) is used #18898

@vrobert78

Description

@vrobert78

Pimcore version

12.2.2

Steps to reproduce

Configure Pimcore to save files through flysystem to S3 or GCS.
Run bin/console pimcore:assets:add-to-update-task-queue to generate the document previews.

Inspect the logs of the worker, you'll find: pimcore.ERROR: Gotenberg\Exceptions\GotenbergApiErrored: Invalid form data: no form file found for extensions: [.123 .602 .abw .bib .bmp .cdr .cgm .cmx .csv .cwk .dbf .dif .doc .docm .docx .dot .dotm .dotx .dxf .emf .eps .epub .fodg .fodp .fods .fodt .fopd .gif .htm .html .hwp .jpeg .jpg .key .ltx .lwp .mcw .met .mml .mw .numbers .odd .odg .odm .odp .ods .odt .otg .oth .otp .ots .ott .pages .pbm .pcd .pct .pcx .pdb .pdf .pgm .png .pot .potm .potx .ppm .pps .ppt .pptm .pptx .psd .psw .pub .pwp .pxl .ras .rtf .sda .sdc .sdd .sdp .sdw .sgl .slk .smf .stc .std .sti .stw .svg .svm .swf .sxc .sxd .sxg .sxi .sxm .sxw .tga .tif .tiff .txt .uof .uop .uos .uot .vdx .vor .vsd .vsdm .vsdx .wb2 .wk1 .wks .wmf .wpd .wpg .wps .xbm .xhtml .xls .xlsb .xlsm .xlsx .xlt .xltm .xltx .xlw .xml .xpm .zabw]

The reason is that the file located on S3 is downloaded in the var/tmp folder as .tmp file and passed to Gotenberg with the .tmp extension. As Gotenberg checks the file extension, the file is refused as .tmp is not supported.

A quick and dirty hack in lib/Document/Adapter/Gotenberg.php solves the issue:

            // ---- QUICK & DIRTY DEBUG HACK ----
            $originalFilename = $asset->getFilename();
            $ext = pathinfo($originalFilename, PATHINFO_EXTENSION);

            // Fallback if something weird happens
            if (!$ext) {
                $ext = 'docx';
            }

            $localAssetTmpPathWithExt = $localAssetTmpPath . '.' . $ext;

            // Copy temp file to same location with correct extension
            if (!file_exists($localAssetTmpPathWithExt)) {
                copy($localAssetTmpPath, $localAssetTmpPathWithExt);
            }

            // Use the new path for Gotenberg
            $localAssetTmpPath = $localAssetTmpPathWithExt;
            // ---------------------------------

Actual Behavior

DOCX document previews not generated.

Expected Behavior

DOCX document previews generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions