Sergio Gonzalez
Sergio Gonzalez

Reputation: 79

How to send an audio file in Cordova using ajax?

Is there any way to send a mp3 file to server in Cordova using ajax?

Thanks.

Upvotes: 1

Views: 302

Answers (3)

Sergio Gonzalez
Sergio Gonzalez

Reputation: 79

Thanks. I had seen that. But i had a problem when i tried to save the mp3 file on back-end.

I'm using this java rest (using MultipartHttpServletRequest):

@RequestMapping(value="/{clientId}/conversation/", method = RequestMethod.POST)
        @ResponseBody String chat(@PathVariable("clientId") String clientId, HttpSession session, MultipartHttpServletRequest request){}

But i don't know how to save this mp3 file on disk? Do i need to apply some Encoder?

Note: In Cordova i used options.mimeType="audio/mpeg";

Upvotes: 0

Jamil
Jamil

Reputation: 939

You have use cordova-file-transfer plugin

Example:

var transfer = new FileTransfer();
transfer.upload(FILE_ABSOLUTE_PATH, "http://example.com/upload", function(sucess){
  // success callback
  console.log(success);
 }, function(fail){
  // failure callback
  console.error(fail);
 });

example on absolute path in Android : /storage/emulated/0/Android/data/.....

Upvotes: 1

looffee
looffee

Reputation: 81

use cordova-file-transfer plugin

Upvotes: 0

Related Questions