Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Image not uploading from iphone.

$
0
0

Hello guys, I am stuck in a very very strange situation. I am just trying to upload a simple image on my server but I always get 404 Not Found HTTP Error. This happens on iphone only. Android works fine. Following is my code: Titanium:

Titanium.Media.openPhotoGallery({
    success:function(event) {
        /* success callback fired after media retrieved from gallery */
        Ti.API.info('Image selected. Now uploading...');
        var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'testImg.jpg');
        file.write(event.media)
        var xhr = Titanium.Network.createHTTPClient();
        xhr.onload = function(e) {
            alert(this.responseText);
            Ti.API.info(this.responseText);
        };
        xhr.onerror = function(e){
            alert('Error while uploading ad: '+e.error||null);
            Ti.API.info('Error while uploading ad: '+e.error||null);
            Ti.API.info('e: ',e);
            Ti.API.info('readyState: ',xhr.readyState)
            Ti.API.info('status: ',xhr.status);
            Ti.API.info('statusText: ',xhr.statusText);
        }
        xhr.open('POST','http://www.myServer.com/imageTest.php');
        xhr.setRequestHeader("enctype", "multipart/form-data");
        xhr.send({
             photo:file.read(),  /*event.media      event.media holds blob from gallery */
          });
// works fine if photo parameter is removed.
    },
});
Following is the console output after running above code:
[INFO] :   Image selected. Now uploading...
[INFO] :   Error while uploading ad: HTTP error
[INFO] :   e:  {
[INFO] :       code = 404;
[INFO] :       error = "HTTP error";
[INFO] :       source = "[object TiNetworkClient]";
[INFO] :       success = 0;
[INFO] :       type = error;
[INFO] :   }
[INFO] :   readyState:  4
[INFO] :   status:  404
[INFO] :   statusText:  HTTP/1.1 404 Not Found
This only happens when I include the photo parameter in xhr.send(). If I remove the photo param everything works fine. Also this only happens on my own server. I've tried to upload on another free server and it worked with that server but with my server it always gives the above output. Following is my php code for accepting image on server: PHP:
<?php
    if($_FILES['photo'])
    {
        $name = $_FILES['photo']['name'];
        $size = $_FILES['photo']['size'];
        $tmpPath = $_FILES['photo']['tmp_name'];
        echo 'Image received.\nName: '.$name.'\nSize: '.($size/1024).'kb\npath: '.$tmpPath;
    }else{
        echo "Not received!!!";
    }
?>
I don't understand what is the problem while I've used the same code several times. Any kind of help is appreciated. Thanks

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>