0

I'm trying to convert a cURL command to a retrofit call. The cURL command is:

curl -u {username}:{password} -X POST
--header "Content-Type: audio/wav" 
--header "Transfer-Encoding: chunked" 
--data-binary @{audiofile}.wav 
"{url}" -i -v

I already converted the -u command by adding a Base64 of the username and password as the Authorization header. I've also added the other header. However the problem is with the retrofit call. The Retrofit call is currently:

@POST
@Headers({"Transfer-Encoding: chunked", "Content-Type: audio/wav"})
Call<Station> translateAudio(@Url String url, @Header("Authorization") String auth,
        @Body RequestBody file);

When using the cURL command the audio file gets processed correctly on the server. However when I try the retrofit call I'm getting an error from the service I'm using. It seems there is a difference between the retrofit call and the cURL one. Does anyone know what the difference is? The credentials do get accepted, so that's not the problem.

Marc
  • 1,094
  • 3
  • 17
  • 38
  • What kind of error do you receive? – Jonas Köritz Apr 01 '16 at 13:24
  • @jonas.koeritz: The error is: { "code_description": "Bad Request", "code": 400, "error": "unable to transcode data stream audio/wav -> audio/x-float-array " } However that's specific to that service. Maybe it could help with searching for the difference of sending the file. – Marc Apr 01 '16 at 13:27
  • How do you create your `file` object? – Jonas Köritz Apr 01 '16 at 13:31
  • @jonas.koeritz: I created my file object by using new File(Environment.getExternalStorage()+"/file.wav"). The file is valid and the app has permission to read the file. – Marc Apr 01 '16 at 13:44
  • The cause of the problem might be that retrofit sends the binary representation of the File Object itself, not the Files contents to the server. – Jonas Köritz Apr 01 '16 at 13:46
  • @jonas.koeritz that's a possibility. Do you know perhaps how to send the contents of the file instead of the representation of the File object? – Marc Apr 01 '16 at 13:47

1 Answers1

0

Your code tries to send an Android File Object to the server. You have to read the file into a byte array or other suitable structure first to send the real contents to the server.

See this question for a quick solution how to do this

Community
  • 1
  • 1
Jonas Köritz
  • 2,606
  • 21
  • 33
  • I tried sending the data by byte array however this did not solve the problem. I still get the same response. The method I used to create the RequestBody is RequestBody.create(MediaType.parse("audio/wav"), bytes); – Marc Apr 01 '16 at 14:26