如何解决如何使用 Micronaut 作为客户端将图像文件 (png) 发送到 REST API Post 端点
我将此代码用作 POST API 的客户端
@Produces("image/png")
@Post("/marketplaces/{marketplaceId}/banking/accreditation/holders/{holderId}/documents?type={type}")
fun saveIndividualDocumentHolder(
@Header("Authorization") authorization: String,@PathVariable marketplaceId: String,@PathVariable holderId: String,@PathVariable type: String,@Body image: String
): HttpResponse<HolderDocumentResponse>
API 期望图像文件为“image/png”、“image/jpg”。我收到 {415 Unsupported media type: text/plain"}
我使用以下方式发送“文件”:
fun saveIndividualDocumentHolder(holderId: String,type: String,file: MultipartBody): HttpResponse<HolderDocumentResponse> {
val contentType = "image/png"
val httpResponse = client.saveIndividualDocumentHolder(authorization,marketplaceId,holderId,type,file.toString())
if (httpResponse.status != HttpStatus.CREATED) throw RuntimeException("HTTP status: ${httpResponse.status}" )
val response = httpResponse.body()?: throw RuntimeException("No body")
return httpResponse
}
我使用 MultipartBody 从我的“内部端点”中选择了文件。然后我将此文件转换为字符串作为正文请求。 我对所有这些东西都很陌生,你能解释一下吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。