Skip to main content

Web File Uploader

一個使用 FastAPI 建構的檔案上傳與限時下載服務,下載路徑含 UUID 前綴、到期自動清除。

安裝 uv

如果尚未安裝 uv,請先安裝:

# 使用 pip 安裝 uv
pip install uv

# 或使用官方安裝腳本
curl -LsSf https://astral.sh/uv/install.sh | sh

開發和除錯

使用虛擬環境開發

  1. 安裝依賴到現有的虛擬環境:

    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
    
  2. 啟動開發伺服器(支援自動重新載入):

    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 文檔。

Metadata

Release files for web-file-uploader 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for web-file-uploader 0.2.0
File Size Uploaded Provenance
web_file_uploader-0.2.0.tar.gz 9.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for web-file-uploader 0.2.0
File Interpreter ABI Platform
web_file_uploader-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.5 kB

Release files / web_file_uploader-0.2.0.tar.gz

Download URL web_file_uploader-0.2.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f764841b0e02c31003df3fccb4e15d8e207ea0b1e4c634f13f5135224ecfeff1
BLAKE2b-256 checksum
How to use checksums
696fc01c8c140403ef277db3346dba12f0560e91d71ba7ab77a803db18951437
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / web_file_uploader-0.2.0-py3-none-any.whl

Download URL web_file_uploader-0.2.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e688f574a22873913a431aa852b53fde7b49f795233e5f52f85b792871824a3
BLAKE2b-256 checksum
How to use checksums
c1a2ad8bbbca2932212367e9d7389cd38fde5c8e4f0ed615ce76bb9b7a4fcec8
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for web-file-uploader 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page