Issue
HTTP Post a photo that will be saved at Internal phone storage
Tested on
Droid Razr 2.3.5
Repro steps
1) Run code below & pick up an image from the gallery
2) Wait till the image gets uploaded
3) Go through with any File Manager app to monitor Internal phone storage directory. Notice the uploaded image is present at such location having a similar file name: "tixhr***.jpeg"
Repro sequences
- app.js
Titanium.Media.openPhotoGallery({
success:function(event){
var myImage = event.media;
var xhr = Titanium.Network.createHTTPClient();
xhr.open('POST','http://192.168.0.100/upload.php');
xhr.onerror = function(e){alert(e.error);};
xhr.setTimeout(200000);
xhr.onload = function(e){
Ti.UI.createAlertDialog({title:'Success', message: this.responseText
}).show();
};
xhr.onsendstream = function(e){Ti.API.info(e);};
xhr.setRequestHeader("contentType", "multipart/form-data");
xhr.send({uploadedfile:myImage});
},
cancel:function(){
},
error:function(error){
},
mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
});
- upload.php
<?php
$target_path = "uploadedimages/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
Work around
Walk through all files that start with the name "tixhr" to manually purge them.
Another test case: app.js
upload.php
Test steps: 1. run app.js 2. select an image 3. should see an alert "Success: " 4. check the files in the phone (using something like ASTRO). Before my fix, there are several image files named like "tixhr*.jpeg". After my fix, there are no temporary image files.
PR https://github.com/appcelerator/titanium_mobile/pull/2498
2_1_X PR [2744](https://github.com/appcelerator/titanium_mobile/pull/2744)
Reopening issue to add FixVersion 2.1.2