首页 > 解决方案 > 发布图像对象 Clarifai rest api swift

问题描述

我想上传在 swift 应用程序中捕获的图像,因此图像作为对象我需要通过 http 请求执行此操作首先我尝试使用 curl 执行此操作但我收到一个错误,即字符串太长其次我尝试使用示例代码在网站上发布但不起作用

来自网站的代码示例:

curl -X POST
    -H 'Authorization: Key YOUR_API_KEY'
    -H "Content-Type: application/json"
    -d '
    {
      "inputs": [
        {
          "data": {
            "image": {
              "url": "https://samples.clarifai.com/demographics.jpg"
            }
          }
        }
      ]
    }'

https://api.clarifai.com/v2/models/c0c0ac362b03416da06ab3fa36fb58e3/outputs

我想将图像上传为快速捕获的对象 UIImage,而不是 URL

标签: swiftresthttprequestclarifai

解决方案


尝试以下curl命令:

curl -X POST \
     -H "Authorization: Key YOUR_API_KEY" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d '{"inputs":[{"data":{"image":{"url":"https://samples.clarifai.com/demographics.jpg"}}}]}' \
     https://api.clarifai.com/v2/models/c0c0ac362b03416da06ab3fa36fb58e3/outputs

它似乎对我有用。


推荐阅读