Drop-in controller action for editor uploads.
defmodule MyAppWeb.EditorUploadController do
use MyAppWeb, :controller
use Tiptapex.Upload.Controller,
handler: MyApp.EditorUploads,
max_bytes: 25_000_000,
allowed: ~w(image/png image/jpeg image/gif image/webp video/mp4 video/webm application/pdf),
scope_param: "scope"
endThen mount it inside an authenticated pipeline:
scope "/admin", MyAppWeb do
pipe_through [:browser, :require_authenticated_user]
post "/tiptapex/uploads", EditorUploadController, :create
endThe injected create/2:
- requires a
"file"multipart part; - validates it with
Tiptapex.Upload.Validator(size + magic-byte content-type verification); - builds the context via
build_context/2(overridable — default:%{scope: params[scope_param], params: params, conn_assigns: conn.assigns}); - calls
handler.store/2(yourTiptapex.Uploadimplementation); - replies with the JSON contract the JS hook expects
(
{"url", "content_type", "filename"}) or a 422 with an error code.
CSRF: the JS hook sends the x-csrf-token header, which the standard
:browser pipeline (protect_from_forgery) validates — no extra
plumbing needed. Keep the route out of :api-style pipelines that skip
CSRF unless you add your own protection.