Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1310] onsendstream for HttpClient does not update progress properly when sending Blob

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2016-02-01T06:59:33.000+0000
Affected Version/sAppcelerator Studio 4.5.0
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsHttpClient
ReporterStephen Ostrow
AssigneeSharif AbuDarda
Created2016-01-22T20:31:39.000+0000
Updated2016-03-08T07:37:42.000+0000

Description

Below is a simplistic test case. In practice I've done this with large blob data of >10M which showed progress = 1 for a minute over and over again.
var httpClient = Ti.Network.createHTTPClient({
    onload: function() {
        Ti.API.debug("Upload file responseText: " + this.responseText);
    },
    onerror: function(e) {
        Ti.API.error("Error uploading file: " + e.error);
        Ti.API.debug("Upload file responseText: " + this.responseText);
    },
    onsendstream: function(e) {
        var progress = parseFloat(e.progress);
        Ti.API.trace("Upload progress: " + 100 * progress);
    }
});

httpClient.open('POST', 'https://example.org');

// e.progress returns as expected 0.0 - 1.0
var args = {'field1': 'value1'};
httpClient.send(args);


// e.progress will only return 1
var args = Ti.createBuffer({value: 'fields: value1'}).toBlob();
httpClient.send(args);

Comments

  1. Sharif AbuDarda 2016-01-24

    Hello, Can you provide a full code and data file that you are uploading. We will try to reproduce it in our environment. Assuming you have a server-side service which accepts file uploads, you should find upload fairly straightforward. Titanium already upload a file as a blob if it's a image file. I was trying the below uploading image file code and it's working as expected.
       var form_url = 'http://apps.priyo.com/jonopriyo/image.php';
       	var win = Ti.UI.createWindow({
       		layout : 'vertical',
       		backgroundColor : '#fff'
       	});
       
       	var btnPhoto = Ti.UI.createButton({
       		title : 'Select Photo'
       	});
       	btnPhoto.addEventListener('click', function(e) {
       		// Open photo gallery for user to select photo
       		Ti.Media.openPhotoGallery({
       			mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
       			success : function(e) {
       				btnPhoto.value = e.media;
       				anImageView.image = e.media;
       				btnPhoto.title = '[ Photo Selected ]';
       			},
       			cancel : function() {
       				btnPhoto.value = null;
       				btnPhoto.title = 'Select Photo...';
       			},
       			error : function(err) {
       				Ti.API.error(err);
       				btnPhoto.value = null;
       				btnPhoto.title = 'Select Photo...';
       			}
       		});
       	});
       	win.add(btnPhoto);
       
       	var btnSubmit = Ti.UI.createButton({
       		title : 'Submit'
       	});
       	btnSubmit.addEventListener('click', function(e) {
       
       		var c = Titanium.Network.createHTTPClient({
       			onload : function(e) {
       
       				Ti.API.info('this.responseText' + this.responseText);
       				json = JSON.stringify(this.responseText);
       				alert(this.responseText);
       			},
       			onerror : function(e) {
       				alert(JSON.stringify(e));
       			},
                               onsendstream : function(e) {
                                   var progress = parseFloat(e.progress);
                                   Ti.API.info("Upload progress: " + 100 * progress);
               }
       		});
       		c.open('POST', form_url);
       		Ti.API.info('form_url ' + encodeURI(form_url));
       		//        c.setRequestHeader('Content-Type', 'multipart/form-data');
       		c.send({
       			userid : 81,
       			image : btnPhoto.value
       		});
       	});
       	win.add(btnSubmit);
       	var anImageView = Ti.UI.createImageView({
       
       	});
       	anImageView.addEventListener('load', function() {
       		Ti.API.info('Image loaded!');
       	});
       
       	// Add to the parent view.
       	win.add(anImageView);
       	win.open();
       
    Please provide a complite project that demonstrate the issue. ANd steps to reproduce. Thanks.

JSON Source