[英]How to upload Audio (Mp3) to Server Using Retrofit2 Android
How to upload an audio file by retrofit?如何通过改造上传音频文件?
I brought some of the classes and code I wrote, but I did not respond to these codes我带来了一些我写的类和代码,但是我没有回应这些代码
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);
Class :班级 :
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();
}
});
How to upload an audio file by retrofit?如何通过改造上传音频文件?
I brought some of the classes and code I wrote, but I did not respond to these codes我带来了一些我编写的类和代码,但是我没有对这些代码做出回应
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);
Class :班级 :
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();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.