1. Are you ready for the Galaxy S20? Here is everything we know so far!

Titanium SDK: Image Upload

Discussion in 'Android Development' started by AndroidDeveloper501, Aug 16, 2010.

  1. AndroidDeveloper501

    Thread Starter

    Hi everyone, I'm new here :)

    I have a problem that is bugging me very much, I have to solve it very urgently, but nobody replies on the Appcelerator forums so I found this one on Google and thought I give it a try.

    I'm using a webview, and I'm calling titanium events from the javascript inside the webview. I need to upload images from the photo gallery, or camera, to my server.

    Here is my code:

    Code (Text):
    1.  
    2. var image;
    3.  
    4. Ti.App.addEventListener('select_button', function()
    5. {
    6.     Titanium.Media.openPhotoGallery({
    7.  
    8.         success:function(event)
    9.         {
    10.             image = event.media;
    11.         },
    12.         cancel:function(){},
    13.         error:function(){},
    14.         allowImageEditing:true
    15.     });
    16. });
    17.  
    18. Ti.App.addEventListener('upload_button', function()
    19. {
    20.     var xhr = Titanium.Network.createHTTPClient();
    21.  
    22.     xhr.onerror = function(e){alert('Error');};
    23.     xhr.setTimeout(200000);
    24.     xhr.onload = function(e){alert(this.responseText)};
    25.     xhr.onsendstream = function(e){};
    26.     xhr.open('POST','http://domain.com/upload');
    27.     xhr.send({media:image,title:'test'});
    28. });
    I'm calling the events defined above from inside the webview like this:

    Code (Text):
    1.  
    2. <p onclick='send("select_button");return false;'>Select Button</p>
    3. <p onclick='send("upload_button");return false;'>Upload Button</p>
    4. <script>
    5. function send(event) {
    6.     Ti.App.fireEvent(event);
    7. }
    8. </script>
    I have TWO problems, first and most important, when I choose an image, everythings fine, and I click "Upload", the log shows this:

    paste.ly - 5Sf


    SECOND, how can I make the WebView <-> titanium communication NOT interrupted by clicking a link inside the WebView ?
    (thus, going to another page, this other page also has the event callers, but they are not working.)


    Thanks in advance...
     


Loading...
Similar Threads - Titanium SDK Image
  1. The Juan
    Replies:
    0
    Views:
    97
  2. jay1976
    Replies:
    0
    Views:
    388
  3. DirectionsDev
    Replies:
    0
    Views:
    390
  4. Paul Mathias
    Replies:
    1
    Views:
    481
  5. mici37000
    Replies:
    1
    Views:
    1,232
  6. Android News
    Replies:
    0
    Views:
    557
  7. Android News
    Replies:
    0
    Views:
    521
  8. Diane_DM
    Replies:
    6
    Views:
    188
  9. odatkid
    Replies:
    1
    Views:
    2,878
  10. ck722
    Replies:
    3
    Views:
    528

Share This Page

Loading...