axum-impl-file-upload

Implement multipart/form-data file uploads in Axum handlers with bounded memory and body limits.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-file-upload
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: axum-impl-file-upload
Source: https://github.com/Impertio-Studio/Axum-Claude-Skill-Package/tree/main/skills/source/axum-impl/axum-impl-file-upload
Command: npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-file-upload

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you implement reliable Axum file-upload endpoints that accept real multipart/form-data uploads while enforcing safe body limits, correct extractor ordering, streaming to avoid memory blowups, and proper handling of MultipartError instead of production panics.

Core Features & Use Cases

  • Correct multipart handler structure: Ensures Multipart is the only body-consuming extractor and is the last handler argument, preventing compile-time failures and runtime misbehavior.
  • Safe iteration and field reading: Drives next_field() until Ok(None) and reads field metadata (name/filename/content-type) before consuming the body via bytes(), text(), or chunk().
  • Body limit and DoS resistance: Uses DefaultBodyLimit (and when needed RequestBodyLimitLayer) to avoid default 2MB rejections, prevent unbounded uploads, and return appropriate 413-class behavior.
  • Secure file handling: Avoids path traversal by never trusting file_name() for destination paths, and prefers streaming chunk() into tokio::fs::File to keep peak memory bounded.

Quick Start

Use the axum-impl-file-upload skill to design a production-ready Rust handler for /upload that streams an uploaded file to disk safely, sets a clear request body ceiling, and returns a 400 response on malformed multipart bodies instead of panicking.

Frequently Asked Questions about axum-impl-file-upload

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle multipart file uploads in Axum without hitting the 2MB body limit?

Axum multipart file uploads fail with a 413 error when exceeding the default 2MB limit. You must override this by applying DefaultBodyLimit or RequestBodyLimitLayer to set an explicit request body ceiling for your upload routes.

Why does my Axum multipart upload panic or return errors at runtime?

Axum multipart uploads panic or error when extractors are ordered incorrectly or fields are consumed improperly. Ensure Multipart is the last handler argument, read metadata before consuming the body, and handle MultipartError explicitly instead of panicking.

What is the best way to stream large file uploads to disk in Axum?

The best way to stream large file uploads to disk in Axum is using the chunk() method. Iterate through next_field() until Ok(None), read field metadata first, and stream chunks directly into a tokio::fs::File to keep peak memory bounded.

How do I prevent path traversal vulnerabilities with file_name() in Axum uploads?

To prevent path traversal vulnerabilities in Axum uploads, never trust the file_name() output for constructing destination paths. Always generate safe destination paths independently and stream the uploaded file content securely to disk.

Can I mix small text fields and large file streams in a single Axum multipart request?

Yes, you can mix small buffered fields and large file streams in a single Axum multipart request. Process small fields using bytes() or text() while streaming large file bodies via chunk() to maintain bounded memory usage throughout the operation.

Does Axum require the Multipart extractor to be the last argument in a handler?

Yes, Axum requires the Multipart extractor to be the last argument in a handler. Because Multipart is a body-consuming extractor, placing it earlier causes compile-time failures or runtime misbehavior with other extractors.