upload file

You must Login before you can answer or comment on any questions.

Hi,

I want to upload image : here is my code :

exports.addMediaToAlbum = function(idAlbum, media, name, description, success, error){
 
    var client = Ti.Network.createHTTPClient();
    client.open('POST', 'https://server.com/api/photo/');
    client.setRequestHeader('Content-Type', 'multi-part/form-data');
 
    var id;
 
    client.onerror = function(e){
        error(e.error);
    };
 
    client.onload = function(e) {
        try{
            var response = this.responseText;
            //alert(response);
            success();
        }   
        catch(Err){
            error(Err);
        }
    };
 
    client.send({album: idAlbum, photo: media, name: name, description: description});
};
i try to send but it doesn't work. i have the same code width curl in php and it works :
$file = new File('/path/to/file.jpg');
        $fields = array(
            "photo" => "@".$file->getRealPath(),
            "name" => "superbe",
            "description" => "un super souvenir !",
            "album" => $album[0]['id']
        );
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        $result = curl_exec($ch);
shoud l add information to my http request object ?

thanks..

— asked 8 months ago by Djamel ZAHAL
2 Comments
  • can anyone help me please ?

    — commented 8 months ago by Djamel ZAHAL

  • I think I've said this to you before, but "it doesn't work" IS NOT a valid problem statement on this QA board. If something doesn't work, you need to be providing error logs, console output, and any environmental information that is relevant. In this case, it would probably be great to know what the output on the server side is as well. It might be key in figuring out why "it doesn't work". Not providing this information is the reason that your question has 50 views and 0 answers.

    FYI, you NEVER have the same code in php and javascript. These 2 entities have almost nothing in common. So assuming that something should work in javascript because you've got basically the same code in php will get you absolutely nowhere.

    — commented 8 months ago by Anthony Decena

Your Answer

Think you can help? Login to answer this question!