空手道多部分文件数组使用已弃用的多部分/混合内容类型



当我上传如下文件数组

Given path 'files', 'multiple'
And multipart file files = { read: 'test.pdf', filename: 'upload-name1.pdf', contentType: 'application/pdf' }
And multipart file files = { read: 'test.pdf', filename: 'upload-name2.pdf', contentType: 'application/pdf' }
When method post
Then status 202

使用multipart/mixed内容类型添加文件,例如:

Content-Type: multipart/form-data; boundary=176626466ce00050
--176626466ce00050
content-disposition: form-data; name="files"
content-type: multipart/mixed; boundary=892503f32da73ceb
--892503f32da73ceb
content-disposition: attachment; filename="upload-name1.pdf"
content-type: application/pdf
content-transfer-encoding: binary
...
--892503f32da73ceb
content-disposition: attachment; filename="upload-name2.pdf"
content-length: 553202
content-type: application/pdf
content-transfer-encoding: binary
...
--892503f32da73ceb--
--176626466ce00050

multipart/mixed在RFC2388中定义,但后来在RFC7578中被弃用,因此一些服务器(如Jetty)将不支持它。是否有可能覆盖默认行为,并使用多个form-data内容配置代替?我使用的是空手道1.3.0,我很确定这不是早期版本的问题

我无法模拟这个,所以也许你应该遵循这个过程:https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

这是我尝试过的:

* url 'https://httpbin.org/post'
* multipart file foo1 = { read: 'test.pdf', contentType: 'application/pdf' }
* multipart file foo2 = { read: 'test.pdf', contentType: 'application/pdf' }
* method post

您可以从响应中看到服务器检测到2个多部分文件,并且看起来一切正常。

我还看到空手道在请求有效负载的地方打印这个:

Mixed: content-disposition: form-data; name="foo1"; filename="test.pdf"
content-type: application/pdf; charset=UTF-8
content-length: 6514
Completed: true
IsInMemory: true
Mixed: content-disposition: form-data; name="foo2"; filename="test.pdf"
content-type: application/pdf; charset=UTF-8
content-length: 6514
Completed: true
IsInMemory: true

所以对我来说,它看起来很好,或者无法复制。我们只是使用Netty来构建多部分的有效负载。如果我们使用Netty错误或Netty有bug,欢迎您深入研究代码并推荐(或贡献PR)。

为了完整起见,1.3.1提供了另一种支持文件数组的方法,因此您可以尝试这种方法:

* url 'https://httpbin.org/post'
# just use the same name, and behind the scenes an array of multi-parts will be sent in the request body 
* def first = { name: 'foo', read: 'test.pdf', contentType: 'application/pdf' }
* def second = { name: 'foo', read: 'test.pdf', contentType: 'application/pdf' }
# note how we support an array of files, which can be programmatically built
# here we use enclosed javascript (refer docs) for convenience, note the round-brackets
* multipart files ([ first, second ])
* method post

相关内容

  • 没有找到相关文章

最新更新