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

Uploading file to android via XHR not working

$
0
0

Hey Guys,

Have looked at other posts and this may just be an issue that is unresolved. I am able to upload photos using the code below through iOS, however in android the image never makes it to the my rails server. The user hits showGallery on a click function and then selects a button to postIssues

my_image is a global variable defined in alloy.js

in index.js

function showGallery() {
        Titanium.Media.openPhotoGallery({
            success:function(event)
            {
                //getting media
                my_image = event.media;
 
                //checking if it is photo
                if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
                {
                    Ti.App.Properties.setString("image", my_image.nativePath);
                    $.imageView.image = my_image;
                }  
            },
        });
   }
 
 
function postIssues() {
    xhr.open("POST", rails_url);    
    xhr.setRequestHeader('enctype','multipart/form-data');
    xhr.setRequestHeader('Content-type',"image/png");
    Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
    Titanium.Geolocation.purpose = "GPS user coordinates";
 
    Titanium.Geolocation.getCurrentPosition(function(e)
    {
        if (e.error)
        {
                alert(e.error);
                return;
        }
 
        var params = {
        user: '1',
        media: my_image, 
        title: $.titleField.value, 
        description:$.descriptionField.value,
        latitude: e.coords.latitude,
        longitude: e.coords.longitude
        };
 
        xhr.send(params);
    });
The oddest thing is that this works find in iOS but not Android. The phone i am using is 4.4

Viewing all articles
Browse latest Browse all 8068

Trending Articles



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