Can't upload images except to TwitPic
We've asked this query again and again, BUT i think there is no way out.
Our web application takes images as multipart image data. We upload images using HTML's simple <input type="file"…>
However, its jut impossible to do this using appcelerator.
All samples are related to twitpic, I don't know what server side they are using!
Here is my code for uploading image
$(function(){
function postPic(pic) {
if (Titanium.Network.NETWORK_NONE) {
console.log('No Network Connection');
}else{
// var query = 'https://twitpic.com/api/uploadAndPost';
var query = 'https://localhost/index.php/common/uploadphoto';
var xhr = Titanium.Network.createHTTPClient();
xhr.onreadystatechange = function() {
console.log("state change");
if (this.readyState == 4) {
console.log("state change to ready" );
}else{
console.log("state change to un known");
}
};
xhr.open('POST',query);
xhr.send({
userid:"5",
uploadtype:"mainphoto",
media:pic
// username: "test", // password: "test", // message: "message value"
});
}
};
$("#b").click(function() {
Titanium.Media.openPhotoGallery({
success: function(image,details){
postPic(image);
},
error: function(error){
console.log('Error came');
},
cancel: function(){
console.log('Cancelled');
},
allowImageEditing:true
});
});
});
1 Answer
-
When you pass a blob to XHR like this, it will send it as
multipart/form-data
. Make sure your expecting that on your accessing the file from the$_FILES
property of PHP.