Skip to content

Practical guide

Build a file-upload form in Twidget

Connect a page form to a multipart upload endpoint, show useful loading and error states, and verify the saved file before displaying success.

1. Prepare the upload endpoint and a harmless test file

This guide connects a Twidget page to an existing single-file endpoint. For backend setup, first follow create a file-upload API. You need a dedicated development workspace, a published test endpoint and a small synthetic text file such as sample-note.txt. Avoid personal documents while testing.

Inspect the endpoint input and output rather than guessing their names. Write down the multipart file field, required metadata and the response property containing the stored-file reference. Decide whether the file is public or private. A protected upload endpoint does not automatically make a public file private.

2. Add a named file input inside the form

Open Pages and create or edit a test page. Add a form, a file input and an associated submit action. Put the file input inside the form and give it the same name as the endpoint expects. Only inputs nested in the form contribute to the form payload. Start with one file; multiple-file handling has a different contract.

Add a short instruction describing the intended file type and your application limit. Client hints help selection, but enforce required file, size, type and access rules on the backend as well. Do not trust a filename extension as proof of file contents.

Twidget page editor showing an Add your next task form with title and status inputs
Existing synthetic Marketing task form in the page editor. Reuse the form pattern with the fields in this guide; this is not the new form or an executed save.

3. Connect the submit function using multipart data

Create a page function and connect it to form submission. Configure its HTTP request to use the endpoint's method and URL, mapping the selected file into form data under the agreed field name. Send the bytes, rather than a filename string or an ordinary JSON object. Include authentication when the endpoint requires it.

Let the browser/request command construct the multipart boundary. A manually supplied Content-Type: multipart/form-data header without its matching boundary can make an otherwise valid upload unreadable. Map each additional field individually; storage permissions and destination must follow server policy, not arbitrary browser input. Watch upload files using Pages for the page-side workflow.

Page function inputs showing Page, Path, Query, Event and Form contexts
Existing page-function controls in Marketing. They illustrate input mapping; this new page workflow has not been configured or executed.
Workflow command search showing the File Manager Upload file command separately from provider uploads
Existing Marketing command picker showing File Manager Upload file. This identifies storage commands; it does not show multiple-file generation or a successful upload.

4. Separate pending, failure and verified success

Use page variables to represent pending state, a safe error message and the saved-file result. Clear the old result when a new submission starts, and prevent a second submit while the first is pending. Only display success after a successful response with the expected reference. A local filename preview only confirms selection.

If the request fails, restore the submit action and explain whether the user should choose another file or retry. Keep private tokens, internal storage paths and raw exception traces out of the message. For private files, use the application's authorized retrieval workflow instead of rendering an assumed public URL.

5. Check the stored result and rejected requests

TestExpected result
Small allowed test fileOne successful response and a matching item in File Manager
No file selectedUseful validation message; no new file
Disallowed or oversized fileBackend rejection; no success message
Expired sessionDenied request; user can recover without losing context
Double submitSecond action prevented while pending

Read back or download only your own synthetic fixture through the intended access path and compare its contents. Test after publishing too: a working draft function is separate from the public page and endpoint. No new upload execution is claimed by the configuration screenshots in this article.

6. Diagnose common integration failures

If the backend sees no file, compare the form input name, multipart key and endpoint file input. If only the browser fails, inspect the response and configured frontend origin; follow the browser-access checks in connect a frontend. A successful upload with an unusable link usually calls for reviewing the returned reference, storage permissions and retrieval contract.

Continue with multiple-file uploads when your single-file journey is reliable. Twidget's web app builder brings the form and backend together; review current plan allowances for your project.

Go deeper

Supporting documentation

Find the configuration details and reference material behind this page.

From idea to a working flow

Build one useful thing with Twidget

Start with a small workflow, test it with sample data and make it your own.

Preview

Have any questions? Get in Touch

Starting with Twidget is easy, fast and free

It only takes a few clicks to get started

Get started - it's free

No credit card required.


© Copyright 2026 - Twidget.io