Titanium Community Questions & Answer Archive

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

Can't upload images except to TwitPic

We've asked this query again and again, BUT i think there is no way out.

Our web application takes images as multipart image data. We upload images using HTML's simple <input type="file"…>

However, its jut impossible to do this using appcelerator.

All samples are related to twitpic, I don't know what server side they are using!

Here is my code for uploading image

$(function(){

function postPic(pic) {

    if (Titanium.Network.NETWORK_NONE) {

        console.log('No Network Connection');

    }else{

// var query = 'https://twitpic.com/api/uploadAndPost';

        var query = 'https://localhost/index.php/common/uploadphoto';
        var xhr = Titanium.Network.createHTTPClient();

        xhr.onreadystatechange = function() {
            console.log("state change");
            if (this.readyState == 4) {
                console.log("state change  to ready" );
            }else{
                console.log("state change  to un known");
            }   
        };
        xhr.open('POST',query);
        xhr.send({
            userid:"5",
            uploadtype:"mainphoto",
            media:pic

// username: "test", // password: "test", // message: "message value"

        });

    }
};

$("#b").click(function() {      

    Titanium.Media.openPhotoGallery({
        success: function(image,details){

            postPic(image);
        },
        error: function(error){
            console.log('Error came');  
        },
        cancel: function(){
            console.log('Cancelled');   
        },
        allowImageEditing:true
    });
});

});
— asked March 20th 2010 by Hussain Fakhruddin
0 Comments

1 Answer

  • When you pass a blob to XHR like this, it will send it as multipart&#x2F;form-data. Make sure your expecting that on your accessing the file from the $_FILES property of PHP.

    — answered March 20th 2010 by Jeff Haynie
    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.