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

使用CURL调用OctoAI图片放大接口遇报错求助

解决OctoAI图片放大接口的CURL调用问题

问题1:Base64临时文件传递解码失败

报错{"message":"Error decoding provided base64 image in 'init_image' field. Base64 string is not a valid image."},核心原因是生成的Base64字符串含换行符、多余前缀,或是CURL传递方式有误。

解决步骤:

  1. 生成纯净Base64字符串:用-w 0参数禁止自动换行,避免字符串被分割导致解码失败:
    base64 -w 0 input.png > temp_base64.txt
    
    注意:不要给Base64添加data:image/png;base64,这类前缀,接口仅需纯Base64内容。
  2. 正确构造JSON请求:用jq组装JSON(避免手动拼接的转义问题),再通过CURL发送:
    curl -X POST https://api.octoai.run/v1/images/upscale \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d "$(jq -n --arg img "$(cat temp_base64.txt)" '{init_image: $img, width: 1024}')"
    
    也可直接读取文件到JSON字段(需确保Base64无特殊字符):
    curl -X POST https://api.octoai.run/v1/images/upscale \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d "{\"init_image\":\"$(cat temp_base64.txt)\",\"width\":1024}"
    

问题2:大图片Base64传参触发Argument list too large

这是系统命令行参数长度有限制导致的,大图片的Base64字符串过长,超出了参数长度上限。

解决步骤:

用临时JSON文件存储请求体,让CURL直接读取文件内容,绕过命令行参数长度限制:

  1. 生成纯净Base64(同问题1第一步)
  2. 生成完整请求体JSON文件:
    jq -n --arg img "$(cat temp_base64.txt)" '{init_image: $img, width: 1024}' > request.json
    
  3. 用CURL发送请求:
    curl -X POST https://api.octoai.run/v1/images/upscale \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d @request.json
    

简化写法:

无需单独生成Base64临时文件,一步生成JSON并发送:

jq -n --arg img "$(base64 -w 0 input.png)" '{init_image: $img, width: 1024}' > request.json
curl -X POST https://api.octoai.run/v1/images/upscale \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d @request.json

内容的提问来源于stack exchange,提问作者Pedro Emanuel

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 11:03:36