A FastAPI web file uploader
Project description
Web File Uploader
一個使用 FastAPI 建構的檔案上傳與限時下載服務,下載路徑含 UUID 前綴、到期自動清除。
安裝 uv
如果尚未安裝 uv,請先安裝:
# 使用 pip 安裝 uv
pip install uv
# 或使用官方安裝腳本
curl -LsSf https://astral.sh/uv/install.sh | sh
開發和除錯
使用虛擬環境開發
-
安裝依賴到現有的虛擬環境:
cd web-file-uploader & ..\venv\Scripts\Activate.ps1 # 若 uv 在 Windows 碰到 editable 安裝問題,改用 pip 並關閉隔離 python -m pip install -e .[dev] --no-build-isolation --config-settings editable_mode=compat # 或 uv:uv pip install -e .[dev] --no-build-isolation --config-settings editable_mode=compat
-
啟動開發伺服器(支援自動重新載入):
uvicorn main:app --reload --host 0.0.0.0 --port 8000
使用 uvx 部署
在專案目錄中執行:
uvx --from . web-file-uploader
這將安裝依賴並啟動 FastAPI 伺服器在 http://localhost:8000
API 端點(符合 file-expiry 計畫)
GET /: 歡迎訊息和 API 文檔鏈接POST /upload: 上傳檔案,伺服器統一設定有效期,建立紀錄並回傳下載 URL:/download/{uuid}/{filename}GET /download/{uuid}/{filename}: 依 UUID+檔名驗證,未過期且檔案存在才回傳,否則 404 並清理紀錄/檔案GET /files: 列出未過期檔案(含下載 URL、到期時間)DELETE /files/{filename}: 刪除指定檔案
設定與行為
- 預設有效期:60 秒,可由
--expire-seconds或環境變數EXPIRE_SECONDS調整(範圍 10–86400,超界會 clamp) - 清理排程:預設每 300 秒執行一次,可用
--cleanup-interval-seconds或CLEANUP_INTERVAL_SECONDS(範圍 30–3600) - 即時清理:下載時若發現過期或檔案缺失即刪除紀錄/檔案
- 持久化:SQLite(自動建立
file_records.db),重啟後仍可判斷到期
測試
- 執行整合測試:
python -m pytest tests/integration/test_file_expiry.py -q # 或全部測試 python -m pytest -q
API 文檔
啟動伺服器後,訪問 http://localhost:8000/docs 查看完整的互動式 API 文檔。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file web_file_uploader-0.2.0.tar.gz.
File metadata
- Download URL: web_file_uploader-0.2.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f764841b0e02c31003df3fccb4e15d8e207ea0b1e4c634f13f5135224ecfeff1
|
|
| MD5 |
2d84c2bc121ca8cc1774d9f5a21f4193
|
|
| BLAKE2b-256 |
696fc01c8c140403ef277db3346dba12f0560e91d71ba7ab77a803db18951437
|
File details
Details for the file web_file_uploader-0.2.0-py3-none-any.whl.
File metadata
- Download URL: web_file_uploader-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e688f574a22873913a431aa852b53fde7b49f795233e5f52f85b792871824a3
|
|
| MD5 |
e3144ff148933ccc925a1feea57a6e7d
|
|
| BLAKE2b-256 |
c1a2ad8bbbca2932212367e9d7389cd38fde5c8e4f0ed615ce76bb9b7a4fcec8
|