🍡 mochi

File Upload

multipart/form-data submission with server-side validation. With the enhance attachment, the file content is shown inline; without it the page re-renders with the result from the form snapshot.

The action reads a .txt or .md file from multipart/form-data and echoes its name and content back via success(). With {@attach enhance(...)} the content appears inline; without it the page re-renders with the file content from the form snapshot.

With {@attach enhance(...)}

The enhance attachment submits multipart/form-data over fetch and shows the file content inline

No file chosen

Plain HTML

Plain multipart POST, page re-renders with the file content from the form snapshot

<script lang="ts">
  import FileUpload from './FileUpload.svelte';
</script>

<p>
  The action reads a <code>.txt</code> or <code>.md</code> file from <code>multipart/form-data</code> and echoes its name and content back via <code>success()</code>. With
  <code>{'{@attach enhance(...)}'}</code> the content appears inline; without it the page re-renders with the file content from the form snapshot.
</p>
<h3>With <code>{'{@attach enhance(...)}'}</code></h3>
<FileUpload label="The enhance attachment submits multipart/form-data over fetch and shows the file content inline" mochi:hydrate />
<h3>Plain HTML</h3>
<FileUpload label="Plain multipart POST, page re-renders with the file content from the form snapshot" />
Styles
<style>
  h3 {
    margin: 1.5rem 0 0.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
  }

  p {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
  }

  code {
    background: var(--code-bg);
    color: var(--code-accent);
    padding: 0.05rem 0.35rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.85rem;
  }
</style>