AutoSkill 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.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/fastapi-base64-image-form-submission" ~/.claude/skills/ecnu-icalk-autoskill-fastapi-base64-image-form-submission && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/fastapi-base64-image-form-submission/SKILL.mdsource content
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
- Frontend Structure: Use a standard HTML
with<form>
andmethod="post"
.enctype="multipart/form-data" - Selection Mechanism: Display images (e.g., as Base64 thumbnails) and allow selection via checkboxes.
- 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.
- State Management: Implement a mechanism (e.g., a simple JS
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.onchange - Backend Handling: The FastAPI endpoint must accept form data using
orForm(...)
.Request.form() - Data Processing: The backend must extract the lists of names and Base64 strings, decode the Base64 strings into bytes (using
), and convert them into image formats (usingbase64.b64decode
withPIL.Image.open
orio.BytesIO
) for further processing.cv2.imdecode
Anti-Patterns
- Do not use JavaScript
to manually construct and send the JSON or FormData payload if the user explicitly requested standard form submission.fetch - 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