I have a strange error that sometimes occurs in my WinJS application on the RAM emulator for Windows Phone 8.1 512MB. I could not play it on other emulator instances or on the device.
Execution is done through a promise chain and completes the following return statement:
return ( currentUpload = uploadOperation.startAsync() );
After that, nothing happens. I set breakpoints on all three functions (success, failure, pending expectations) that are given to the .then definition. None of these three functional codes will ever be reached when this strange case occurs.
I also put this return statement in a catch try block, but there was no exception for catch.
short code description:
Background loader instance created (custom headers + PUT method)
StorageFile opens with URI
The background loader prepares to download this file (definition of uploadOperation)
uploadOperation will be launched
see full code:
var currentUpload; // global function uploadFile(localFullPath, headers, serverUrl) { var fileUri = new Windows.Foundation.Uri('ms-appdata:///local' + localFullPath), uploader = false; try { uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader(); uploader.method = 'PUT'; // set headers to uploader for (var key in headers) { if (headers.hasOwnProperty(key)) uploader.setRequestHeader(key, headers[key]); } } catch (e) { // error handling return false; } Windows.Storage.StorageFile.getFileFromApplicationUriAsync(fileUri) .then(function success(file) { return uploader.createUpload(serverUrl, file); }, function failure(error) { return WinJS.Promise.wrapError('file not found'); }) .then(function (uploadOperation) { if (currentUpload == 'Canceled') return WinJS.Promise.wrapError('upload canceled'); else return ( currentUpload = uploadOperation.startAsync() ); }) .then(function success(success) { currentUpload = false; // success handling return true; }, function failure(error) { currentUpload = false; // error handling return false; } }, function pending(status) { var progress = status.progress, percent = Math.round(progress.bytesSent / progress.totalBytesToSend * 100); // progress handling }); }
Thanks for any help!
PS I also received an obsolete warning, although I do not use the / TransferGroup in the BackgroundUploader class:
The method Windows.Networking.BackgroundTransfer.IBackgroundTransferBase.put_Group is deprecated. The group may be modified or unavailable for releases after Windows 8.1. Use TransferGroup instead.
Perhaps this is due to this promise chain error.
source share