# RustMultiFileUpload **Repository Path**: aihellow/rust-multi-file-upload ## Basic Information - **Project Name**: RustMultiFileUpload - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-18 - **Last Updated**: 2026-03-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Rust 多文件上传服务 一个基于 Rust + Axum 的高性能多文件上传 HTTP 服务器,支持自定义存储路径、开机自启和 Windows 服务部署。 ## 功能特性 - ✅ 多文件同时上传 - ✅ **自定义文件存储路径**(Windows 绝对路径) - ✅ 自动文件重命名(时间戳 + UUID) - ✅ 文件类型白名单验证 - ✅ 文件大小限制 - ✅ **内置测试接口**(自动生成 CSV/JSON 测试文件) - ✅ Windows 服务支持(开机自启) - ✅ 安装包一键部署 ## 快速开始 ### 1. 构建项目 ```bash cargo build --release ``` ### 2. 运行方式 **方式一:前台运行(调试)** ```bash ./target/release/rust-multi-file-upload.exe ``` **方式二:Windows 服务(生产)** ```bash # 安装服务并设置开机自启 rust-multi-file-upload.exe install # 启动服务 rust-multi-file-upload.exe start # 停止服务 rust-multi-file-upload.exe stop # 卸载服务 rust-multi-file-upload.exe uninstall ``` ### 3. 构建安装包 1. 下载并安装 [Inno Setup 6](https://jrsoftware.org/isdl.php) 2. 运行构建脚本: ```bash installer\build-installer.bat ``` 3. 安装包将生成在 `output/` 目录 ## API 接口 ### 健康检查 **接口:** `GET /health` **请求示例:** ```bash curl http://localhost:8080/health ``` **HTTP 请求:** ```http GET /health HTTP/1.1 Host: localhost:8080 ``` **响应示例:** ```json { "status": "ok", "service": "rust-multi-file-upload", "version": "0.2.0", "timestamp": "2024-01-15T08:30:00+00:00" } ``` --- ### 文件上传 **接口:** `POST /upload` **必须**使用 `path_` 指定 **Windows 绝对路径**(自动创建目录): > ⚠️ **注意**:不指定 `path_` 时,文件将保存到 `/` 目录下(相对路径,不推荐) **请求示例:** ```bash curl -X POST \ -F "config=@app.json" \ -F "database=@backup.sql" \ -F "logs=@server.log" \ -F "path_config=C:\\MyApp\\settings\\prod" \ -F "path_database=C:\\MyApp\\backups\\2024" \ -F "path_logs=C:\\MyApp\\logs\\2024-01-15" \ http://localhost:8080/upload ``` **HTTP 请求:** ```http POST /upload HTTP/1.1 Host: localhost:8080 Content-Type: multipart/form-data; boundary=----WebKitFormBoundary ------WebKitFormBoundary Content-Disposition: form-data; name="path_config" C:\MyApp\settings\prod ------WebKitFormBoundary Content-Disposition: form-data; name="path_database" C:\MyApp\backups\2024 ------WebKitFormBoundary Content-Disposition: form-data; name="config"; filename="app.json" Content-Type: application/json {"key": "value"} ------WebKitFormBoundary Content-Disposition: form-data; name="database"; filename="backup.sql" Content-Type: application/octet-stream ...SQL content... ------WebKitFormBoundary-- ``` **存储结构:** ``` C:\MyApp\ ├── settings\prod\ │ └── app_20240115_083000_a1b2c3d4.json ├── backups\2024\ │ └── backup_20240115_083001_b2c3d4e5.sql └── logs\2024-01-15\ └── server_20240115_083002_c3d4e5f6.log ``` **响应示例:** ```json { "success": true, "message": "上传完成,成功: 3, 失败: 0", "files": [ { "field_name": "config", "original_name": "app.json", "saved_name": "app_20240115_083000_a1b2c3d4.json", "storage_path": "C:\\MyApp\\settings\\prod", "file_size": 1024, "success": true, "error": null, } ], "total": 3, "success_count": 3, "failed_count": 0 } ``` --- ## 默认配置 | 配置项 | 值 | |--------|-----| | 端口 | `8080` | | 上传目录 | `C:\ProgramData\RustFileUploadService\uploads` | | 最大文件大小 | `10485760` (10MB) | | 允许的文件扩展名 | `json,csv,txt,xml,yaml,yml,log` | ## 项目结构 ``` RustMulFileReceive/ ├── Cargo.toml # Rust 项目配置 ├── src/ │ ├── lib.rs # 核心库代码(HTTP 服务) │ ├── main.rs # 入口(支持服务/前台模式) │ └── service.rs # Windows 服务实现 └── installer/ ├── setup.iss # Inno Setup 安装脚本 └── build-installer.bat # 构建脚本 ``` ## 安装包功能 安装包 (`RustFileUploadService-1.0.0-Setup.exe`) 会自动完成: 1. 安装服务到 `C:\Program Files\RustFileUploadService` 2. 注册为 Windows 服务并设置为自动启动 3. 创建上传目录 `C:\ProgramData\RustFileUploadService\uploads` 4. 配置 Windows 防火墙放行 8080 端口 5. 启动服务 卸载时会自动停止服务并清理所有文件。 ## 技术栈 - **Rust** - 系统编程语言 - **Axum** - 现代 Web 框架 - **Tokio** - 异步运行时 - **Tracing** - 结构化日志 - **windows-service** - Windows 服务支持 - **Inno Setup** - 安装包制作 ## 更新日志