TinyMCE images are now uploaded to server storage
Problem
When admins inserted images into TinyMCE rich-text editors (letter templates, document parts, etc.), those images were stored as base64-encoded data URIs directly in the saved HTML content. This caused significant database row bloat and log noise — a single embedded image could add hundreds of kilobytes to a record.
How it works
Images inserted via the TinyMCE toolbar are now uploaded to the server via a new POST /admin/tinymce_assets endpoint before the content is saved. The uploaded file is stored privately on local disk (never a public S3/fog bucket, since these images can appear in sensitive documents like contracts and letters of offer), downscaled to a 1600px max width, and TinyMCE inserts a signed <img src="..."> URL reference in the document instead of a base64 string.
The upload happens automatically as soon as an image is selected — no change to the editor UI.
Technical details
New model:
FundingSystem::TinymceImagewith a CarrierWave uploader storing to a private (non-web-accessible) local directory.New controller:
FundingSystem::Admin::TinymceAssetsController:#create— admin-authenticated, returns{ location: signed_url }JSON.#show— intentionally unauthenticated; the URL's signature (anActiveSupport::MessageVerifiertoken) is the credential instead of admin login, since embedded images are fetched anonymously by wkhtmltopdf (PDF export) and by external recipients opening emailed documents. Document-context uploads get a short-lived token that's reissued on every render (PdfExporter::Base#refresh_tinymce_asset_tokens!); email and other non-refreshed contexts get a non-expiring token.
TinyMCE's
images_upload_handlerandfile_picker_callbackoptions handle the async upload and URL substitution before content is serialised.
Last updated
Was this helpful?