I'm running a Machine Learning model on a server that works with WAV files. Can I send WAV files stored in mobile phone through HTTP requests with Android Studio, in WAV form?
So far I'm making (get) requests using retrofit2 like this:
MainActivity.java:
private void getbuttonclicked() {
Call call = RequestManager.INSTANCE.getService().getChords();
call.enqueue((Callback)(new Callback() {public void onResponse(@NotNull Call call, @NotNull Response response) {
Intrinsics.checkParameterIsNotNull(call, "call");
Intrinsics.checkParameterIsNotNull(response, "response");
if (response.isSuccessful()) {
((TextView) findViewById(R.id.output_text)).setText("REQUEST OK");
}
}
DataManager.kt:
object RequestManager {
val interceptor = HttpLoggingInterceptor()
val client = OkHttpClient.Builder().addInterceptor(interceptor).build()
init {
interceptor.level = HttpLoggingInterceptor.Level.BODY
}
val retrofit = Retrofit.Builder()
.baseUrl("http://myip/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
val service = retrofit.create(Api::class.java)
}
Api.kt:
interface Api {
@GET(".")
fun getChords(): Call<chord_model>
}
chord_model.java:
public class chord_model {
@SerializedName("Chords")
@Expose
private List<String> chords = null;
@SerializedName("Bass")
@Expose
private List<String> bass = null;
public List<String> getChords() {
return chords;
}
public void setChords(List<String> chords) {
this.chords = chords;
}
public List<String> getBass() {
return bass;
}
public void setBass(List<String> bass) {
this.bass = bass;
}
}
I suppose I'll have to use post requests, but how do I send a whole file?
You should check this article:
https://www.c-sharpcorner.com/article/upload-files-to-server-using-retrofit-2-in-android/
Basically you'll be sending a POST request. Using postman,it would be something like this:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.