Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (android)
Viewing all articles
Browse latest Browse all 7655

Android HttpClient.abort() does not stop file upload

$
0
0

Hey guys,

I'm having an issue with canceling http uploads from an android device. I have seen in other threads comments about the abort() method not working in Android, but with no replies or solutions. In my case, I have a simple program that uploads an image you select from the gallery. After 5 seconds it will attempt to abort the upload, but the call to abort() has no effect. The upload completes and even triggers the onload callback upon completion. I've tried this with 10+ meg images, so the uploads run long enough that the 5 second abort occurs well before the end of the file transfer. I've also gone so far as to call this.abort() inside the onsendstream callback, but the client keeps on running. What is going on?

Here's my code, you'll have to modify the hostname and upload script name. I just used the receiving php script for uploads from here to test this issue.

var oRequest = {};
 
function UploadAbort() { 
    Ti.API.log('ABORT UPLOAD');  
    oRequest.abort(); 
    oRequest = null; 
}
 
function UploadStart(oData) {
    var i=0;
    var threshold=500;
    oRequest = Titanium.Network.createHTTPClient({ 
        onload: function(e) {
            Ti.API.log('UploadStart : onload : ' + this.responseText);
        },
        onerror: function(e) {
            Ti.API.log('UploadStart : onerror : ' + this.responseText);
        },
        onsendstream: function(e) {
            i+=1;
            if (i >= 500) {
                i=0;
                Ti.API.log('transferring...');
            }
        },
        timeout : 3000
    });
    oRequest.open('POST', 'http://YOURHOSTNAME/UPLOADSCRIPT.php?');
    oRequest.send({image : oData});
    setTimeout(UploadAbort, 5000);
};
 
 
var win = Titanium.UI.createWindow({  
    backgroundColor:'#000'
});
win.open();
 
Ti.Media.openPhotoGallery({
    mediaTypes: [Titanium.Media.MEDIA_TYPE_PHOTO],
    success: function(e) {
        Ti.API.log("back from image gallery ");
        UploadStart(e.media);
    }
});
I've been fighting with this one for quite awhile, so any help is appreciated.

Viewing all articles
Browse latest Browse all 7655

Trending Articles



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