如何使用Akka-Http Client上传带有Multipart.FormData的HttpEntity.Chunked

时间:2017-11-25 13:30:32

标签: scala akka akka-http

在Multipart Form中尝试将大文件作为chunked entity上传到服务器时:

   val chunked = HttpEntity.Chunked.fromData(mimeType, sourceOfByteString)

Multipart.FormData(
      Multipart.FormData.BodyPart("downloadPath", HttpEntity(fileResourceRequest.downloadPath.path)),
      Multipart.FormData.BodyPart("fileSize", HttpEntity(fileResourceRequest.fileSize.toString)),
      Multipart.FormData.BodyPart("data", chunked, Map("filename" → "content"))
    ).toEntity()

我收到此错误:

  

类型不匹配:预期的BodyPartEntity,实际的HttpEntity.Chunked

手动添加 Transfer-Encoding:chunked header时,Akka-http会根据文档删除它。

我能够使用curl

成功执行完全相同的上传
curl -i -X POST \
   -H "Content-Type:multipart/form-data" \
   -H "Authorization:Bearer BB3F8B79384D08B9F268F21FF76ABFA" \
   -H "Transfer-Encoding:chunked" \
   -F "downloadPath=/user-data/media/dachi.png" \
   -F "fileSize=733830" \
   -F "data=@\"./dachi.png\";type=image/png;filename=\"dachi.png\"" \
 'http://0.0.0.0:8000'

0 个答案:

没有答案