【发布时间】:2019-08-23 12:15:39
【问题描述】:
问题是这样的。我正在发送一个音乐文件。我不断收到错误422。由于这个原因,我似乎无法正确定位我的身体
Content-Disposition: form-data; name="Content-Disposition: form-data;
name="audio[file]"; filename="tr.mp3""
Content-Transfer-Encoding: binary
Content-Type: audio/mpeg
Content-Length: 6028060
还有我的代码
@Multipart
@Headers({"Content-Type: multipart/form-data;", "Accept:application/json, text/plain, */*"})
@POST("audios")
Call<SoundResponse> saveSound(@Part ("Content-Disposition: form-data; name=\"audio[file]\"; filename=\"tr.mp3\"") RequestBody file,
@Query("auth_token") String authToken);
并调用了这个方法
RequestBody body = RequestBody.create(MediaType.parse("audio/mpeg"), file);
GeoService.saveSound(body,SoundResponseCallback, getAuthToken());
我也找到了这个东西
Send file to server via retrofit2 as object
在我看来问题在于该字段看起来像这样“音频 [文件]”
感谢您的帮助
【问题讨论】:
-
你的意思是你正在发送一个音频文件,而不是从服务器请求它?
-
所以我发送文件
标签: android retrofit2 multipart