gpt4 book ai didi

scala - FakeRequest withMultipartFormDataBody "Missing boundary header"

转载 作者:行者123 更新时间:2023-12-01 17:35:48 36 4
gpt4 key购买 nike

我正在用 Play 2.6 编写 Controller 测试

我有一个在测试场景之外绝对有效的文件上传但是当我做一个虚假的请求时,我陷入了困境:

A client error occurred: Missing boundary header

这是我的要求:

    def createMultipartFile(file: File) : MultipartFormData[TemporaryFile] = {
MultipartFormData(Map[String,Seq[String]](),
List(FilePart("file","",Some("Content-Type: multipart/form-data"),SingletonTemporaryFileCreator.create(file.toPath))), List())
}
val data = createMultipartFile(sampleCSV)
val controller = app.injector.instanceOf[RefundableController]
val request = FakeRequest().withMultipartFormDataBody(data)
val result = controller.func().apply(request)
assert(status(result) === 200)

尝试手动添加标题,但显然行不通

我应该如何添加边界?

最佳答案

当我简单地将 withMultipartFormDataBody 更改为 withBody 时,它很有帮助。找到这个想法here .

关于scala - FakeRequest withMultipartFormDataBody "Missing boundary header",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49258502/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com