gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 00:06:51 29 4
gpt4 key购买 nike

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

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

接口(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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com