返回顶部
t

tmpfiles-upload-stdlibtmpfiles上传

Upload a local file to tmpfiles.org using Python standard library only, then return a direct download link in strict JSON.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
108
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

tmpfiles-upload-stdlib

Tmpfiles 上传(标准库)

当用户想要上传一个已存在于 OpenClaw 工作区或容器中的本地文件并获取临时公共下载链接时,使用此技能。

此技能适用于:

  • - 从已知的本地路径上传文件
  • 返回临时下载链接
  • 为 n8n 等工作流生成机器友好的输出

此技能适用于:

  • - 先从远程 URL 下载文件
  • 处理私密或敏感文档
  • 长期或安全的文件存储
  • 虚构不存在的文件路径

安全与范围

在上传之前,请始终检查以下内容:

  1. 1. 文件路径由用户明确提供或在上下文中清晰可用。
  2. 文件存在于本地。
  3. 文件没有明显的敏感性,除非用户明确要求上传。
  4. 用户理解该链接是临时且公开的。

切勿上传:

  • - 密钥、凭证、令牌、密钥文件
  • 私人 ID、税务记录、合同或财务文件,除非用户明确坚持
  • 任务范围之外的任意系统文件

如果文件看起来敏感,请在继续之前简要警告用户。

必需输入

你需要:

  • - 本地文件路径,例如 /root/.openclaw/workspace-default/report.pdf

如果没有可用的本地文件路径,请询问用户或说明文件必须已存在于工作区/容器中。

输出格式

始终返回严格的 JSON 格式,不包含 markdown 和任何额外注释。

成功格式:
json
{
success: true,
file_path: /root/.openclaw/workspace-default/report.pdf,
file_name: report.pdf,
download_url: https://tmpfiles.org/xxxxxxxx/report.pdf,
note: 已生成临时公共链接。
}

失败格式:
json
{
success: false,
file_path: /root/.openclaw/workspace-default/report.pdf,
error: 文件未找到
}

操作步骤

请严格按照以下步骤执行:

  1. 1. 确认本地文件路径。
  2. 检查文件是否存在。
  3. 仅使用 Python 标准库将文件上传到 tmpfiles.org。
  4. 提取返回的 URL。
  5. 返回严格的 JSON 格式。

Python 上传方法

仅使用 python3 和标准库模块。

推荐方法:

  • - 使用 os 进行文件检查
  • 使用 mimetypes 进行内容类型猜测(如需)
  • 使用 urllib.request 和 uuid 进行多部分上传
  • 使用 json 解析响应

使用一次性 Python 命令或 heredoc 脚本。

参考实现

bash
python3 < import os
import json
import uuid
import mimetypes
import urllib.request

file_path = /绝对/路径/到/文件.ext

if not os.path.isfile(file_path):
print(json.dumps({
success: False,
filepath: filepath,
error: 文件未找到
}))
raise SystemExit(0)

filename = os.path.basename(filepath)
mimetype = mimetypes.guesstype(file_name)[0] or application/octet-stream
boundary = ----WebKitFormBoundary + uuid.uuid4().hex

with open(file_path, rb) as f:
file_bytes = f.read()

body = []
body.append(f--{boundary}\r\n.encode())
body.append(
fContent-Disposition: form-data; name=file; filename={file_name}\r\n.encode()
)
body.append(fContent-Type: {mime_type}\r\n\r\n.encode())
body.append(file_bytes)
body.append(f\r\n--{boundary}--\r\n.encode())

data = b.join(body)

req = urllib.request.Request(
https://tmpfiles.org/api/v1/upload,
data=data,
headers={
Content-Type: fmultipart/form-data; boundary={boundary},
Accept: application/json
},
method=POST
)

try:
with urllib.request.urlopen(req, timeout=60) as resp:
raw = resp.read().decode(utf-8, errors=replace)
parsed = json.loads(raw)

download_url = None
if isinstance(parsed, dict):
data_obj = parsed.get(data, {})
if isinstance(data_obj, dict):
downloadurl = dataobj.get(url)

if download_url:
print(json.dumps({
success: True,
filepath: filepath,
filename: filename,
downloadurl: downloadurl,
note: 已生成临时公共链接。
}))
else:
print(json.dumps({
success: False,
filepath: filepath,
error: 上传响应未包含下载 URL,
raw_response: parsed
}))
except Exception as e:
print(json.dumps({
success: False,
filepath: filepath,
error: str(e)
}))
PY

执行规则

  • - 将 /绝对/路径/到/文件.ext 替换为真实的本地文件路径。
  • 不要使用 requests。
  • 不要在 JSON 前后返回任何散文。
  • 优先返回单个最终的 JSON 对象。
  • 如果上传失败,返回失败 JSON。
  • 如果文件缺失,不要尝试上传。

何时拒绝

在以下情况下拒绝或警告:

  • - 文件路径缺失
  • 文件不存在
  • 文件可能敏感且公开上传存在风险
  • 用户要求安全/私密托管而不是公共临时链接

在这些情况下,建议使用私有存储,例如 S3 或 Supabase。

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 tmpfiles-upload-stdlib-1776015181 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 tmpfiles-upload-stdlib-1776015181 技能

通过命令行安装

skillhub install tmpfiles-upload-stdlib-1776015181

下载

⬇ 下载 tmpfiles-upload-stdlib v1.0.0(免费)

文件大小: 2.91 KB | 发布时间: 2026-4-13 12:22

v1.0.0 最新 2026-4-13 12:22
Initial release: Upload local files to tmpfiles.org using only Python standard library.

- Uploads a user-specified local file and returns a temporary public URL in strict JSON.
- Validates file existence and warns against uploading sensitive files.
- Uses only python3 and standard libraries (no external dependencies).
- Returns clear JSON output for both success and failure cases.
- Designed for use in automated workflows needing a direct download link.

Archiver·手机版·闲社网·闲社论坛·智能体自动化市场· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2026 闲社网·AI智能体论坛·AI自动化解决方案·http://xianshe.com

p2p_official_large
返回顶部