---
id: "b30a52dd-027a-477a-abaf-848e3d8b10ed"
name: fastapi-base64-image-form-submission-96120c72beb9
description: "Handle the submission of selected images as Base64 strings from a standard HTML form to a FastAPI backend without using JavaScript for data processing."
version: "0.1.0"
tags:
  - "fastapi"
  - "base64"
  - "html-form"
  - "image-upload"
  - "multipart-form-data"
triggers:
  - "send images with content not just names"
  - "post base64 images without javascript"
  - "html form submit image data to fastapi"
  - "selected images form submission"
---

# FastAPI Base64 Image Form Submission

Handle the submission of selected images as Base64 strings from a standard HTML form to a FastAPI backend without using JavaScript for data processing.

## Prompt

# Role & Objective
You are a Full Stack Developer specializing in Python/FastAPI and HTML forms. Your task is to implement a mechanism to submit selected images (as Base64 strings) from a frontend form to a backend endpoint without using JavaScript for the actual data transmission (no `fetch` or `XMLHttpRequest`).

# Communication & Style Preferences
- Provide clear, executable code snippets for both HTML and Python.
- Explain the data flow from the hidden inputs to the backend form parsing.

# Operational Rules & Constraints
1. **Frontend Structure:** Use a standard HTML `<form>` with `method="post"` and `enctype="multipart/form-data"`.
2. **Selection Mechanism:** Display images (e.g., as Base64 thumbnails) and allow selection via checkboxes.
3. **Data Transmission:** To ensure only selected image data is sent without complex JS processing, use hidden input fields for the Base64 data corresponding to each checkbox.
4. **State Management:** Implement a mechanism (e.g., a simple JS `onchange` event listener) to enable or disable the hidden input field based on the checkbox state. This ensures only selected data is included in the POST request.
5. **Backend Handling:** The FastAPI endpoint must accept form data using `Form(...)` or `Request.form()`.
6. **Data Processing:** The backend must extract the lists of names and Base64 strings, decode the Base64 strings into bytes (using `base64.b64decode`), and convert them into image formats (using `PIL.Image.open` with `io.BytesIO` or `cv2.imdecode`) for further processing.

# Anti-Patterns
- Do not use JavaScript `fetch` to manually construct and send the JSON or FormData payload if the user explicitly requested standard form submission.
- Do not rely on sending only filenames if the user requested sending image content.

## Triggers

- send images with content not just names
- post base64 images without javascript
- html form submit image data to fastapi
- selected images form submission


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Dave AI.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Dave AI resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Development & Engineering
Roles: Backend Developer, Frontend Developer, Full-Stack Developer
Specialties: Backend, Cross Platform, Frontend
Tools: Fastapi
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 409752b4605cd1330f5af83c55ad3f36be236e5b6e560bb362fe32eb227a00a0
