[英]How to upload Audio (Mp3) to Server Using Retrofit2 Android
如何通過改造上傳音頻文件?
我帶來了一些我寫的類和代碼,但是我沒有回應這些代碼
界面:
@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();
}
});
所有文件,無論是音頻、視頻、圖像……在改造方面基本相同。 它們只是文件。 接口像任何其他文件一樣用@MultiPart.Part
注釋。 查看此鏈接了解更多詳情。
如何通過改造上傳音頻文件?
我帶來了一些我編寫的類和代碼,但是我沒有對這些代碼做出回應
界面:
@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();
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.