You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将指定curl命令转换为等价的Node.js实现代码?

将Adobe PSD渲染接口的curl请求转为Node.js代码

原curl请求说明

这是调用Adobe Photoshop API创建PSD文件渲染图的POST请求,包含认证信息、输入文件地址和多格式输出配置。

现有代码的问题修正

你的代码思路正确,但存在几处语法和配置错误:

  • 模板字符串里的变量引用需要用${}包裹,否则$token会被识别为普通文本
  • Content-Type的值必须用字符串包裹,不能直接写application/json
  • fetch发送JSON请求体时,必须把对象转为JSON字符串,否则接口无法解析请求内容

修正后的完整代码

// 替换为你的实际令牌和API密钥
const token = "你的Bearer令牌";
const apiKey = "你的API密钥";

const url = "https://image.adobe.io/pie/psdService/renditionCreate";
const options = {
  method: "POST",
  headers: {
    Authorization: `Bearer ${token}`,
    "x-api-key": apiKey,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    inputs: [
      {
        href: "<替换为签名的GET地址>",
        storage: "<替换为存储类型>"
      }
    ],
    outputs: [
      {
        href: "<替换为签名的POST地址1>",
        width: 512,
        storage: "<替换为存储类型>",
        type: "image/jpeg"
      },
      {
        href: "<替换为签名的POST地址2>",
        storage: "<替换为存储类型>",
        type: "image/png"
      }
    ]
  })
};

// 需在async函数内使用await
async function callPsdRenderApi() {
  try {
    const response = await fetch(url, options);
    const result = await response.json();
    console.log("接口响应:", result);
  } catch (error) {
    console.error("请求出错:", error);
  }
}

callPsdRenderApi();

关于inputs和outputs的说明

  • inputs数组:配置待处理的源PSD文件,href为可访问的签名GET地址,storage对应你的存储服务类型
  • outputs数组:定义每个输出渲染图的参数,包括存储地址(href)、尺寸(width)、存储类型(storage)和文件格式(type),结构和原curl中-d参数完全对应

更新说明

已成功调用该接口,后续会发布完整代码。

内容的提问来源于stack exchange,提问作者1.21 gigawatts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 19:02:44