Search code examples
javascriptandroidappceleratortitanium-mobile

Unable to upload photo using Appcelerator Cloud Services (ACS)


I am trying to upload a photo using ACS, but I am getting some runtime error. Here is the code that I am using:

var image;
function uploadPhoto(){
Titanium.Media.openPhotoGallery({
    success: function(e){
    //  alert(e.mediaType);
        if(e.mediaType == Ti.Media.MEDIA_TYPE_PHOTO){
           image = e.media;
           alert(image);

           Cloud.Photos.create({
                photo: Titanium.Filesystem.getFile(image)
            }, function(e){
                if(e.success){
                    var photo = e.photos[0];
                    alert('Success:\n' +
                        'id: ' + photo.id + '\n' +
                        'filename: ' + photo.filename + '\n' +
                        'size: ' + photo.size,
                        'updated_at: ' + photo.updated_at);
                }else{
                    alert('Error:\n' +
                    ((e.error && e.message) || JSON.stringify(e)));
                    alert("Code: "+e.code);
                }
            });
       }
    },
    cancel: function(){

    },
    error: function(err){
        alert("ERROR: "+err);
    },
    mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
});
}

I am running on Android device and when I try to upload any image, I am getting the following error:

Error: Invalid photo file attachment
Code: 400

Can anyone tell me the solution?

Thanks! :)


Solution

  • this line

    photo: Titanium.Filesystem.getFile(image)
    

    should just be

    photo: image