在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'