php - 如何使用 Retrofit2 Android 将音频 (Mp3) 上传到服务器

标签 php android retrofit

如何通过改造上传音频文件?

我带了一些我写的类和代码,但是我没有响应这些代码

接口(interface):

 @Multipart
    @POST("comments")
    Call<Wallet> setComent(@Part("voice") RequestBody song, @Part("api_token") String api_token, @Part("product") String product, @Part("body") String body);

类:

 AudioSavePathInDevice =
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/" +
                        "NAME" + "AudioRecording.mp3";


    File file = new File(AudioSavePathInDevice );

                    //creating request body for file
                    RequestBody requestFile = RequestBody.create(MediaType.parse("audio/*"), file);

                    MyInterFace myInterFace = MyServices.createService(MyInterFace.class);
                    Call<Wallet> calling = myInterFace.setComent
                            (requestFile,new AppStore(getContext()).LoadMyShereKES(AppStore.Keys_TOKEN),AppStore.ID_BACHGROUD,Ediet.getText().toString());

                    calling.enqueue(new Callback<Wallet>()
                    {
                        @Override
                        public void onResponse( Call<Wallet> call,  Response<Wallet> response)
                        {
                            appStore.CloseDilag();
                        }

                        @Override
                        public void onFailure(Call<Wallet> call, Throwable t)
                        {

                            appStore.CloseDilag();
                        }
                    });

enter image description here

最佳答案

所有的文件,无论是音频、视频、图片……基本上都是一样的retrofit。它们只是文件。与任何其他文件一样,该接口(interface)使用 @MultiPart.Part 进行注释。 检查this链接了解更多详情。

关于php - 如何使用 Retrofit2 Android 将音频 (Mp3) 上传到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50399891/

相关文章:

android - 如何使用 Retrofit2 获取带有邮政编码 JSON 正文的地址列表

php - 使用 PHP 解码 JSON

php - 字符串中的 HTML 中断标记在浏览器中显示为 <br>,但也显示为 <br> 开发控制台

php - 通过 preg_match_all PHP 函数从 html 代码字符串中提取 img 标签

android - 进程 'command' 以非零退出值完成

android - PendingIntent 错误(必须是 : PendingIntent. FLAG_ONE_SHOT 中的一个或多个......)

android - 如何使用 ADB 从 android 设备中提取 sqlite 数据库?

android - Okclient中的okclient无法应用于(okhttp3.okhttpclient)

java - _POST[] 删除所有+号

android - 带有改造 API 的 MalformedJsonException?