用途:面向 Frappe 框架的文件与附件管理,覆盖上传、读取、删除、权限控制及云存储配置。
主要能力:提供 save_file、save_url、frappe.get_file、get_file_path、frappe.attach_print 等接口;支持通过 POST /api/method/upload_file 上传;File DocType 含 file_name、file_url、is_private、attached_to_doctype 等字段;公开文件路径为 /files/{filename},私有文件为 /private/files/{filename}。
权限模型:管理员不受限;公开文件(is_private=0)任何持链接者可读;私有文件(is_private=1)需为所有者、被显式分享,或对关联文档有读权限。敏感数据应始终设为私有。
用法示例:save_file(fname, content, dt, dn);save_url(file_url, fname, dt, dn);frappe.get_doc({"doctype": "File", ...}).insert();curl -X POST https://site.example.com/api/method/upload_file -H "Authorization: token api_key:api_secret" -F "file=@/path/to/document.pdf"。
限制:默认单附件上限 10 MB,可在 site_config.json 用 max_file_size 覆盖;自定义存储需实现 delete_file_data_content 钩子并测试删除;版本差异见 v14/v15/v16 对比。