Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 23rd, 2012  |  syntax: JavaScript  |  size: 1.18 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         uploadPickedFile_Chrome: function(inSender, inValue) {
  2.                 try {
  3.                         var formData = new FormData(inSender.$.form.getNode());
  4.                         var headers = false;
  5.                        
  6.                         if (SOME CONDITION THAT WILL REQUIRE HEADERS) {
  7.                                 headers = true;
  8.                         }
  9.                        
  10.                         // sample extra form data
  11.                         formData.append('key', value);
  12.                        
  13.                         var xhr = new XMLHttpRequest();
  14.                         xhr.open('POST', PATH, true);
  15.                        
  16.                         if (headers === true) {
  17.                                 var reqHeaders = {
  18.                                         header: 'value'
  19.                                 };
  20.                                 for (var header in reqHeaders) {
  21.                                         xhr.setRequestHeader(header, reqHeaders[header]);
  22.                                 }
  23.                         }
  24.                        
  25.                         xhr.onreadystatechange = enyo.bind(this, this.checkChromeUpload, xhr);
  26.                         xhr.send(formData);
  27.                 } catch(e) {
  28.                         this.log("ERROR!");
  29.                         this.log(e);
  30.                 }
  31.                 this.$.uploaderFilePicker.close();
  32.         },
  33.         checkChromeUpload: function(xhr) {
  34.                 if (xhr.readyState === 4 && xhr.status === 200) {
  35.                         this.successfulUpload({}, {completed: true, responseString: xhr.responseText}, {});
  36.                 } else if (xhr.status > 200) {
  37.                         // it failed, handle with an error message, or re-do the upload (set a flag to do this only once and only on the PlayBook due to its XHR upload bug)
  38.                 } else {
  39.                         this.log(xhr.readyState, xhr.status);
  40.                 }
  41.         },