загрузить аудио файл с помощью retrofit2 - PullRequest
0 голосов
/ 13 апреля 2019

Я пытаюсь загрузить аудиофайл на сервер с модификацией2.после отправки запроса ответом будет: «message»: «(1007) Неподдерживаемый аудиоформат»

Это информация, которую я отправляю с PostMan:

enter image description here

enter image description here

вот мой код:

InterFace:

 @Multipart
    @POST("audiofile")
    Call<ResponseModel> upload(@Header("X-SessionID") String account , @Part MultipartBody.Part file , @Query("path") String address);

и

 RequestBody requestFile = RequestBody.create(MediaType.parse("audio/*"), file);
        // MultipartBody.Part is used to send also the actual file name
        MultipartBody.Part body =
                MultipartBody.Part.createFormData("voice", file.getName(), requestFile);
        String descriptionString = "hello, this is description speaking";
        RequestBody description =
                RequestBody.create(
                        okhttp3.MultipartBody.FORM, descriptionString);

        Call<ResponseModel> response = requestInterface.upload(session , body , file.getName());
        response.enqueue(new Callback<ResponseModel>() {
            @Override
            public void onResponse(@NonNull Call<ResponseModel> call, @NonNull Response<ResponseModel> response) {

                Log.d("server-", "onResponse: " + new Gson().toJson(response.body()));
            }
            @Override
            public void onFailure(@NonNull Call<ResponseModel> call, @NonNull Throwable t) {
                Log.d("server-", "onResponse: " + t);
            }
        });
...