Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16672] Windows Hybrid: Downloading a file while offline crashes the app

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2014-03-25T19:46:20.000+0000
Affected Version/sn/a
Fix Version/s2014 Sprint 06, 2014 Sprint 06 Tooling, Release 3.3.0
ComponentsWindows Hybrid
Labelsmodule_hybrid, qe-testadded
ReporterChris Barber
AssigneeChris Barber
Created2014-03-23T02:23:48.000+0000
Updated2014-05-20T20:12:23.000+0000

Description

When testing downloading a file using tiwp8.downloadFile() and your device is offline, the app crashes. We need to capture the error and properly throw an exception. On a side note, the XHR proxy seems to report 400 bad request for all requests when offline. That may be ok, but check what other environments do when offline and perhaps throw a better error.

Comments

  1. Chris Barber 2014-03-25

    IMPORTANT API CHANGE!

    downloadFile() signature had to change to accommodate the onerror handler:
       tiwp8.downloadFile({
       	url: 'http://www.ambientreality.com/test.pdf',
       	//saveTo: 'foo.pdf', // tmpFolder.Name,
       	overwrite: true,
       	oncomplete: function (e) {
       		var ea = e.eventArgs,
       			file = ea.property('file'),
       			size = ea.property('size');
       
       		console.log('Finished downloading file to ' + file);
       		console.log('File is ' + size + ' bytes');
       
       		var currentFolder = tiwp8.staticProperty('Windows.Storage.ApplicationData', 'Current'),
       			localFolder = currentFolder.property('LocalFolder');
       
       		// convert the full path to a relative path
       		file = file.replace(localFolder.property('Path') + '\\', '');
       
       		localFolder.invokeAsync('GetFileAsync', ['System.String', file], function (pdfFile) {
       			tiwp8.invokeStaticAsync('Windows.System.Launcher', 'LaunchFileAsync', ['Windows.Storage.IStorageFile', pdfFile], function (success) {
       				console.log('LaunchFileAsync success?', success);
       				currentFolder.destroy();
       				localFolder.destroy();
       				pdfFile.destroy();
       			});
       		});
       	},
       	onerror: function (ex) {
       		alert(ex);
       	}
       });
       
  2. Chris Barber 2014-03-25

    Master pull request: https://github.com/appcelerator/titanium_mobile/pull/5525 3_2_X_hybrid pull request: https://github.com/appcelerator/titanium_mobile/pull/5526
  3. Samuel Dowse 2014-05-14

    Verified fixed on: Windows 8.1 Appcelerator Studio, build: 3.3.0.201405121247 Titanium SDK, build: 3.3.0.v20140514121712 Titanium CLI, build: 3.3.0-dev Windows SDK: 8.0 Nokia Lumia 520: 8.0 PDF file is downloaded successfully while network is connected. App does not crash if network is not connected. Closing.

JSON Source