[TIMOB-16635] NSURLConnection: Download data to file if specified
| GitHub Issue | n/a |
|---|---|
| Type | Sub-task |
| Priority | High |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2014-03-18T17:57:15.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | 2014 Sprint 06, 2014 Sprint 06 SDK, Release 3.3.0 |
| Components | iOS |
| Labels | module_network, qe-closed-3.3.0, qe-testadded |
| Reporter | Pedro Enrique |
| Assignee | Pedro Enrique |
| Created | 2014-03-17T17:58:32.000+0000 |
| Updated | 2014-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.
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(); });PR pending: https://github.com/appcelerator/titanium_mobile/pull/5487
CR + FR
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