Titanium Community Questions & Answer Archive

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

Mobile App Sending Image File to PHP Server

I am trying to send an image file to a php server. What am I doing wrong?


var xhr = Titanium.Network.createHTTPClient();
xhr.open('POST',<url>);
filename = 'img.png';
xhr.send({media: filename});

// Then on the php side I have
$tmpfile = $_FILES['media']['tmp_name']; // ==> to get at the file information
.
.

any and all help is appreciated. Thanks.

— asked March 22nd 2010 by General Usage
  • http-client
  • image
  • mobile
  • titanium.network
0 Comments

3 Answers

  • Hey Rob, Thanks for the response. For others here is the code that works.

    var xhr = Titanium.Network.createHTTPClient();
    xhr.open('POST',<url>);
    filename = 'img.png';
    f1 = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,filename);
    iamge=f1.read(image);
    xhr.send({media: image});
    
    — answered March 22nd 2010 by General Usage
    permalink
    0 Comments
  • In your example filename is a string. You need to send the raw file data over in the send({media:filename})

    — answered March 22nd 2010 by Rob Edgell
    permalink
    0 Comments
  • Hi,
    Can you please help me out in this issue:
    http://developer.appcelerator.com/question/8471/upload-images-to-a-server
    and here:
    http://stackoverflow.com/questions/2532478/how-to-upload-images-from-iphone-app-developed-using-titanium

    — answered March 28th 2010 by Karthik k
    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.