Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9797] Android: HTTP Post will save a photo at Internal phone storage

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-08-14T17:01:43.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sSprint 2012-14 API, Release 2.1.2, Release 3.0.0
ComponentsAndroid
LabelsSupportTeam, api
ReporterEduardo Gomez
AssigneePing Wang
Created2012-06-25T15:19:47.000+0000
Updated2012-08-14T19:23:25.000+0000

Description

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.

Comments

  1. Ping Wang 2012-06-29

    Another test case: app.js
       Titanium.Media.openPhotoGallery({
           success:function(event){
        
               var myImage = event.media;
        
               var xhr = Titanium.Network.createHTTPClient();
               xhr.open('POST','http://10.0.15.40:8888/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, uploadedfile2:myImage, uploadedfile3:myImage});
        
           },
           cancel:function(){
        
           },
           error:function(error){
           },
           mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
       });
       
    upload.php
       <?php
        
       $target_path = "uploadedimages/";
       $target_path1 = $target_path . basename( $_FILES['uploadedfile']['name']); 
       $target_path2 = $target_path . basename( $_FILES['uploadedfile2']['name']); 
       $target_path3 = $target_path . basename( $_FILES['uploadedfile3']['name']); 
       
       
       if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path1) && 
       	move_uploaded_file($_FILES['uploadedfile2']['tmp_name'], $target_path2) &&
       	move_uploaded_file($_FILES['uploadedfile3']['tmp_name'], $target_path3))
       
       {
           echo "The file ".  basename( $_FILES['uploadedfile']['name']) .  basename( $_FILES['uploadedfile2']['name']).  basename( $_FILES['uploadedfile3']['name'])." have been uploaded";
       } else{
           echo "There was an error uploading the file, please try again!";
       }
        
       ?>
       
    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.
  2. Ping Wang 2012-06-29

    PR https://github.com/appcelerator/titanium_mobile/pull/2498
  3. Sabil Rahim 2012-08-14

    2_1_X PR [2744](https://github.com/appcelerator/titanium_mobile/pull/2744)
  4. Sabil Rahim 2012-08-14

    Reopening issue to add FixVersion 2.1.2

JSON Source