Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16635] NSURLConnection: Download data to file if specified

GitHub Issuen/a
TypeSub-task
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-03-18T17:57:15.000+0000
Affected Version/sn/a
Fix Version/s2014 Sprint 06, 2014 Sprint 06 SDK, Release 3.3.0
ComponentsiOS
Labelsmodule_network, qe-closed-3.3.0, qe-testadded
ReporterPedro Enrique
AssigneePedro Enrique
Created2014-03-17T17:58:32.000+0000
Updated2014-07-28T17:06:06.000+0000

Description

If the "file" property is specified, the data of the request must be streamed to that file path. Otherwise, store it in memory. Return a Ti Blob with either the data of the file.

Comments

  1. Pedro Enrique 2014-03-17

    Sample app:
       var win = Ti.UI.createWindow({
       	backgroundColor: '#CCC'
       });
       
       var btn = Ti.UI.createButton({
       	title: 'here',
       	top: 10
       });
       
       win.add(btn);
       
       var img = Ti.UI.createImageView({
       	top: 75, bottom: 20,
       	left: 20, right: 20
       });
       win.add(img);	
       
       win.open();
       
       
       btn.addEventListener('click', function(){
       
       	var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'my_file.jpg');
       	var xhr = Ti.Network.createHTTPClient();
       	xhr.file = file;
       	xhr.onload = function(){
       		img.image = file.read();
       	};
       	xhr.onerror = function(){
       		alert('error')
       	};
       	xhr.open('GET', 'http://upload.wikimedia.org/wikipedia/commons/3/3f/Fronalpstock_big.jpg');
       	xhr.send();
       });
       
  2. Pedro Enrique 2014-03-17

    PR pending: https://github.com/appcelerator/titanium_mobile/pull/5487
  3. Vishal Duggal 2014-03-18

    CR + FR
  4. Paras Mishra 2014-07-17

    Verified the issue using the above app, Image is downloaded to file specified and displayed on the screen. Verified the fix on: Device : iPhone 5s , iOS version : 7.1.2 SDK: 3.3.0.v20140711123603 CLI version : 3.3.0-rc4 OS : MAC OSX 10.9.2 Alloy: 1.4.0-rc5 ACS: 1.0.15 npm:1.3.2 LiveView: 1.0.4 Appcelerator Studio, build: 3.3.0.201407111535 titanium-code-processor: 1.1.1 XCode : 5.1.1

JSON Source