Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

I am trying to upload the files created by the Audio Recorder

Here is the code that I am using:

var start = UI.createButton({title: "Record"});
start.addEventListener('touchstart', function(e) {
  start.title = "Recording...";
start.addEventListener('touchend', function(e) {
  file = recorder.stop();
  start.title = "Recorded: " + file.size;

  var xhr = Titanium.Network.createHTTPClient();

  xhr.onerror = function(e)
    Ti.UI.createAlertDialog({title:'Error', message:e.error}).show();
    Ti.API.info('IN ERROR ' + e.error);
  xhr.onload = function(e)
    Ti.UI.createAlertDialog({title:'Success', message:'status code ' + this.status}).show();
    Ti.API.info('IN ONLOAD ' + this.status + ' readyState ' + this.readyState);
  xhr.onsendstream = function(e)
    Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress);
  // open the client
  xhr.setRequestHeader("Content-Type", "audio/x-wav");

  // send the data


It records, saves a file in the tmp directory with the contents and even reports the correct file size. When I try to upload though, the content length is zero.


— asked October 3rd 2010 by Sam Pullara
  • audio
  • file
  • recording
  • upload
  • xhr

1 Answer

  • Using the source for Titanium Mobile, I figured out it is because the API for TiFile is wrong. I needed to do xhr.send(file.blob) to get the contents. Looks like it is documented as file.read to me.

    — answered October 3rd 2010 by Sam Pullara
    • thank you for this! i needed that last comment very badly!

      — commented November 30th 2011 by Mendel Broekhuijsen
    • I'm trying to upload my audio but on my php it says that my $_FILES['file'] is empty

      can you help me? can you post your .php file to receive the audio ?


      — commented October 1st 2014 by Douglas Hennrich
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.