【问题标题】:Uploading files using Karate REST API tool使用空手道 REST API 工具上传文件
【发布时间】:2018-05-22 08:24:37
【问题描述】:

我正在尝试使用空手道在特定的松弛通道上上传图像,但没有运气,我尝试了多次不同的步骤,但仍然有 200 响应,并且图像未显示在通道中。 尝试发布文字内容,成功找到频道上的文字。

下面是我按照空手道文档进行的 2 次尝试:

@post
Feature: Post images

Background: 
* url 'https://slack.com/api/files.upload'
* def req_params= {token: 'xxxxxxx',channels:'team',filename:'from Karate',pretty:'1'}

Scenario: upload image
Given path 'api','files'
And params req_headers
And multipart file myFile = { read: 'thumb.jpg', filename: 
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field message = 'image upload test'
And request req_headers
When method post
Then status 200

Given path 'files','binary'
And param req_params
And request read('thumb.jpg')
When method post
Then status 200

我错过了什么吗?尝试了在上传 pdf 和 jpg 的空手道演示 GitHub 存储库中找到的相同示例,但没有成功。

注意:使用 Slack API UI 工作。

【问题讨论】:

    标签: rest cucumber-jvm karate


    【解决方案1】:

    您似乎在混淆事情,当您使用multipart 时,不需要request 正文。您的标头/参数看起来不正确。同样基于doc here,文件上传字段的名称是file。试试这个:

    Scenario: upload image
    Given url 'https://slack.com/api/files.upload'
    And multipart file file = { read: 'thumb.jpg', filename: 
    'upload-name.jpg', contentType: 'image/jpg' }
    And multipart field token = 'xxxx-xxxxxxxxx-xxxx'
    When method post
    Then status 200
    

    如果这不起作用,请寻求能够理解如何解释 Slack API 文档的人的帮助。或者让 Postman 测试正常运行,然后你会很容易找出你错过了什么。

    【讨论】:

    • 上面试过了,没有炒锅。使用波纹管 curl 命令工作: curl -F file=@C:/Users/xxx/image.jpg -F channels=team -F token=xoxp-xxxxxx slack.com/api/files.upload 使用 Postman 工作,但使用空手道对我不起作用(表单域...)
    • 好的,你有足够的信息来改变空手道测试。确保您知道表单字段和多部分字段之间的区别。我不太了解 curl -F 的含义。一切顺利:)
    • 谢谢彼得。仅供参考 -f --> - - 形式
    猜你喜欢
    • 1970-01-01
    • 2013-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多