Titanium SDK: Image Upload


  1. AndroidDeveloper501

    AndroidDeveloper501 New Member

    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...

    Advertisement

Share This Page