.. include:: ../Includes.txt .. _upload_postprocess: ============ Post-processing uploads ============ Process uploaded files on-the-fly --------- You can define post-processing operations that are executed after a file has been uploaded. This is useful for: * Randomizing filenames for security * Resizing images on-the-fly * Converting image formats * Compressing images The ``postProcess`` configuration is defined in TypoScript under your file upload configuration: .. code-block:: typoscript plugin.tx_nnrestapi.settings.fileUploads { myconfig { defaultStoragePath = 1:/uploads/ postProcess { 10 { userFunc = Nng\Nnrestapi\Helper\UploadPostProcessHelper::randomizeFilename } 20 { userFunc = Nng\Nnrestapi\Helper\UploadPostProcessHelper::imageMaxWidth maxWidth = 3000 filetype = jpg quality = 70 } } } } Post-processors are executed in order of their numeric keys (10, 20, 30, etc.). --------- Built-in post-processors --------- The extension ships with two built-in post-processors: randomizeFilename ~~~~~~~~~~~~ Renames the uploaded file to a random, unique filename. This is useful for security (hiding original filenames) and preventing filename conflicts. .. code-block:: typoscript postProcess { 10 { userFunc = Nng\Nnrestapi\Helper\UploadPostProcessHelper::randomizeFilename } } The filename will be converted to a format like: ``1734567890123abc456def.jpg`` imageMaxWidth ~~~~~~~~~~~~ Resizes images to a maximum width while maintaining aspect ratio. Also allows converting to a different format and setting compression quality. Requires **ImageMagick** to be installed. .. code-block:: typoscript postProcess { 20 { userFunc = Nng\Nnrestapi\Helper\UploadPostProcessHelper::imageMaxWidth # Maximum width in pixels (required) maxWidth = 3000 # Convert to this format (optional, e.g., jpg, png, webp) filetype = jpg # JPEG compression quality 0-100 (optional, default: 80) quality = 70 } } Features: * Automatically corrects image orientation (EXIF) * Strips metadata for smaller file size * Only resizes if image is larger than maxWidth * Skips non-image files automatically --------- Custom post-processors --------- You can create your own post-processor by defining a static method: .. code-block:: php request->getUploadedFiles(); return ['uploaded' => count($files)]; }