【问题标题】:HTTP request to Cloud-Convert not working对 Cloud-Convert 的 HTTP 请求不起作用
【发布时间】:2020-05-05 19:10:53
【问题描述】:

我正在尝试使用 fetch 向 Cloud Convert 发布 API 调用并收到以下错误:

消息:“给定的数据无效。” 代码:“INVALID_DATA” 错误:{...} 任务:数组(1) 0:“任务字段是必需的。”

这是我的代码(在 Wix 上):

export async function convertMp4toMp3(fileUrl, filename) {
    filename = filename.replace(/mp4/gi, "mp3")
    let job = {
        tasks: {
            "import-2": {
                "operation": "import/url",
                "url": fileUrl
            },
            "task-1": {
                "operation": "convert",
                "input_format": "mp4",
                "output_format": "mp3",
                "engine": "ffmpeg",
                "input": [
                    "import-2"
                ],
                "audio_codec": "mp3",
                "audio_qscale": 0
            },
            "export-1": {
                "operation": "export/google-cloud-storage",
                "input": [
                    "task-1"
                ],
                "project_id": "project-id",
                "bucket": "bucket",
                "client_email": "client_emailXXXXXXX",
                "file": filename,
                "private_key": "My Private Key
            }
        }
    }
    let options = {
        "method": "POST",
        "body": job,
        "headers": {
            "Authorization": "Bearer MyApiKey",
            "Content-type": "application/json"
        }
    }
    let response = await fetch("https://api.cloudconvert.com/v2/jobs", options)
    console.log(response.json())
}

如您所见,“任务”字段中填充了作业...

【问题讨论】:

    标签: fetch-api velo cloudconvert


    【解决方案1】:

    fetch API 不会自动编码 JSON。 试试:

      let options = {
            "method": "POST",
            "body": JSON.stringify(job),
            "headers": {
                "Authorization": "Bearer MyApiKey",
                "Content-type": "application/json"
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-23
      • 2018-04-24
      • 2016-09-21
      • 1970-01-01
      相关资源
      最近更新 更多