Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>"if (progressEvent.lengthComputable) {" has no matching closing bracket.</p> <p>It could be that's broken subsequent methods onUploadSuccess and onUploadError. Or perhaps that's just a typo in your question.</p> <p>Incidentally, it might be good practice to save a FileTransfer reference for each imageURI, rather than using a global reference to a single FileTransfer. Then you could upload multiple photos at once, and still retain the ability to cancel each upload separately, e.g.</p> <pre><code>// basic implementation of hash map of FileTransfer objects // so that given a key, an abort function can find the right FileTransfer to abort function SimpleHashMap() { this.items = {}; this.setItem = function(key, value) { this.items[key] = value; } this.getItem = function(key) { if (this.hasItem(key)) { return this.items[key]; } return undefined; } this.hasItem = function(key) { return this.items.hasOwnProperty(key); } this.removeItem = function(key) { if (this.hasItem(key)) { delete this.items[key]; } } } var fileTransferMap = new SimpleHashMap(); </code></pre> <p>...then in uploadPhoto after creating a new FileTransfer:</p> <pre><code>// register this object so that abort can find it fileTransferMap.setItem(imageURI, ft); </code></pre> <p>...then pass the imageURI in your cancel button:</p> <pre><code>function onStopUploadBtn(imageURI) { var ft = fileTransferMap.getItem(imageURI); if (ft) { console.log('Aborting'); ft.abort(onUploadSuccess, onUploadError); } } </code></pre> <p>...and remember to remove the ft from the map when download is complete, or upon error:</p> <pre><code>fileTransferMap.removeItem(imageURI); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload