Titanium Community Questions & Answer Archive

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

File upload on Android

Does file upload of an image (from gallery or taken with the camera) works for Android platform?

Which version / sample code?

— asked July 12th 2010 by Dalibor Nasevic
  • android
  • fileupload
0 Comments

3 Answers

  • Yep - You can find an example in the KitchenSink reference project.

    — answered July 12th 2010 by David Ashwood
    permalink
    2 Comments
    • Looking at the xhr.js file from KitchenSink it says that xhr_fileupload.js test is 'iPhone OS' only:

      // add iphone specific tests
      if (Titanium.Platform.name == 'iPhone OS')
      {
        data.push({title:'setTimeout', hasChild:true, test:'../examples/xhr_settimeout.js'});
        data.push({title:'File Upload', hasChild:true, test:'../examples/xhr_fileupload.js'});
      }
      

      I tried the twitpic file upload on Android but without any success.

      Any suggestions about file upload on Android?

      — commented July 12th 2010 by Dalibor Nasevic
    • It's working on in the simulator when I tried it a few days ago.
      I'll see if I can find the code.

      — commented July 12th 2010 by David Ashwood
  • This code was working as of 2 mins ago when I tested it

    
    if (Titanium.Network.online) {
        var image = win.toImage();
        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.setTimeout(20000);
        xhr.open('POST','https://twitpic.com/api/uploadAndPost');
        xhr.send({media:image,username:'xxx',password:'yyy',message:'check me out'});
    } else {
        Ti.UI.createAlertDialog({title:'Dude!', message:'Umm - you need to be connected to the network'}).show();    
    }
    

    ofc - you'll need to change xxx & yyy to your own password.

    — answered July 12th 2010 by David Ashwood
    permalink
    1 Comment
    • Thanks David for your answers!

      I succeed to upload twitpic using the code from KitchenSink and using Titanium Mobile version 1.3.2 and using the latest version from Git (1.3.3).

      However, it doesn't work for version 1.3.0 which I actually used before when reporting the problem.

      And also, this code above does not work for me, for any version of the mentioned 3, maybe because of win.toImage() function. I receive status 200, but no image on tweetpic.

      I will further research what's the problem and report the findings here.

      — commented July 13th 2010 by Dalibor Nasevic
  • Does anyone know how to create the webservice (php) similar to

    xhr.open('POST','https://twitpic.com/api/uploadAndPost');

    I want to upload images to my site.

    — answered April 6th 2011 by Saqib Dareshani
    permalink
    0 Comments
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.