I want to send an audio file to a server with retrofit2
. I followed this tutorial but the file is not in the format the server accepts. Based on this tutorial I tried the following:
RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part audio = MultipartBody.Part.createFormData("file", "file", requestBody);
and the interface:
@Headers("Content-Type: application/json")
@Multipart
@POST("app/")
Call<JResponse> upload(@Part("file") RequestBody file);
But, the file:
attribute is not sent. (If I change @Part
with @Body
it exists but then there is another problem)
I want to know how to send a file in following format? Should I convert audio file to base64
format?
{ 'file' : audio_file }