Issue
I read a lot issues with that here, but it's not working for me. May be I doing something wrong?
my retrofit Interface:
@Multipart
@POST("/api/v1/services/add")
suspend fun addServiceAsync(@Part("newService") service: ServiceApiData,
@Part imageFile:MultipartBody.Part?,
@Header("Authorization") jwt:String?): StatusAndStrApi?
And Spring RestController part is
@PostMapping("/add")
ResponseEntity<?> addService(@RequestPart(name = "newService") ServiceServer service,
@RequestPart("imageFileFromClient") MultipartFile imageFile
)
Here how i create Multipatr.Body:
MultipartBody.Part.createFormData(
"imageFileFromClient",
fileImage.name,
fileImage.asRequestBody("image/*".toMediaTypeOrNull()
)
Here what server return me:
I/okhttp.OkHttpClient: <-- 400 http://server:8080/api/v1/services/add (301ms)
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
I/okhttp.OkHttpClient: Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: application/json
I/okhttp.OkHttpClient: Transfer-Encoding: chunked
Date: Fri, 03 Sep 2021 05:11:18 GMT
Connection: close
{"timestamp":"2021-09-03T05:11:18.689+00:00","status":400,"error":"Bad Request","path":"/api/v1/services/add"}
I/okhttp.OkHttpClient: <-- END HTTP (110-byte body)
I/System.out: close [socket][/100.107.22.171:34172]
Solution
BODY WAS NULL, but it mustn't be. Don't allow Multipartbody be nullable. Never.
Answered By - LoliDeveloper
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.