swift - 发布图像对象 Clarifai Rest api swift

标签 swift rest httprequest clarifai

我想上传在 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

最佳答案

尝试以下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

这似乎对我有用。

关于swift - 发布图像对象 Clarifai Rest api swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56321643/

相关文章:

json - `JSONDecoder` 如何知道使用哪种编码?

c# - GWT 将 header 发送到 c# 后端

iOS AF网络 3.0 : Is there a faster way to send multiple API requests and wait until all of it is finished?

ios - Alamofire POST请求错误NSURLErrorDomain代码= -999

javascript - AJAX - 重新加载网页的一部分而不使用单独的文件来加载

iOS Swift UITextfield 调整字体大小宽度

swift - NSPredicate 可以使用不区分大小写的搜索与 Core Data IN 比较吗? ( swift 4)

JSON 编码 NSObject 不是结构?

java - 一个 Web 应用程序中的 Spring MVC 和 Spring WS 调度程序 Servlet 配置

java - 重载包含不同路径变量类型的 RestController 方法