js/cloudmine.js
function(key, options) {
      options = opts(this, options);
      var response = {success: {}}, query;

      if (options.filename) {
        query = {
          force_download: true,
          apikey: options.apikey,
          session_token: options.session_token,
          filename: options.filename
        }
      }

      var apicall = new APICall({
        action: 'binary/' + key,
        type: 'GET',
        later: true,
        encoding: 'binary',
        options: options,
        query: query
      });

      // Download file directly to computer if given a filename.
      if (options.filename) {
        if (isNode) {
          apicall.setProcessor(function(data) {
            response.success[key] = fs.writeFileSync(options.filename, data, 'binary');
            return response;
          }).done();
        } else {
          function detach() {
            if (iframe.parentNode) document.body.removeChild(iframe);
          }
          var iframe = document.createElement('iframe');
          iframe.style.display = 'none';
          document.body.appendChild(iframe);
          setTimeout(function() { iframe.src = apicall.url; }, 25);
          iframe.onload = function() {
            clearTimeout(detach.timer);
            detach.timer = setTimeout(detach, 5000);
          };
          detach.timer = setTimeout(detach, 60000);
          response.success[key] = iframe;
        }

        apicall.done(response);
      } else if (options.mode === 'buffer' && (ArrayBuffer || Buffer)) {
        apicall.setProcessor(function(data) {
          var buffer;
          if (Buffer) {
            buffer = new Buffer(data, 'binary');
          } else {
            buffer = new ArrayBuffer(data.length);
            var charView = new Uint8Array(buffer);
            for (var i = 0; i < data.length; ++i) {
              charView[i] = data[i] & 0xFF;
            }
          }

          response.success[key] = buffer;
          return response;
        }).done();
      } else {
        // Raw data return. Do not attempt to process the result.
        apicall.setProcessor(function(data) {
          response.success[key] = data;
          return response;
        }).done();
      }

      return apicall;
    }
function(key, options) {
      options = opts(this, options);
      var response = {success: {}}, query;

      if (options.filename) {
        query = {
          force_download: true,
          apikey: options.apikey,
          session_token: options.session_token,
          filename: options.filename
        }
      }

      var apicall = new APICall({
        action: 'binary/' + key,
        type: 'GET',
        later: true,
        encoding: 'binary',
        options: options,
        query: query
      });

      // Download file directly to computer if given a filename.
      if (options.filename) {
        if (isNode) {
          apicall.setProcessor(function(data) {
            response.success[key] = fs.writeFileSync(options.filename, data, 'binary');
            return response;
          }).done();
        } else {
          function detach() {
            if (iframe.parentNode) document.body.removeChild(iframe);
          }
          var iframe = document.createElement('iframe');
          iframe.style.display = 'none';
          document.body.appendChild(iframe);
          setTimeout(function() { iframe.src = apicall.url; }, 25);
          iframe.onload = function() {
            clearTimeout(detach.timer);
            detach.timer = setTimeout(detach, 5000);
          };
          detach.timer = setTimeout(detach, 60000);
          response.success[key] = iframe;
        }

        apicall.done(response);
      } else if (options.mode === 'buffer' && (ArrayBuffer || Buffer)) {
        apicall.setProcessor(function(data) {
          var buffer;
          if (Buffer) {
            buffer = new Buffer(data, 'binary');
          } else {
            buffer = new ArrayBuffer(data.length);
            var charView = new Uint8Array(buffer);
            for (var i = 0; i < data.length; ++i) {
              charView[i] = data[i] & 0xFF;
            }
          }

          response.success[key] = buffer;
          return response;
        }).done();
      } else {
        // Raw data return. Do not attempt to process the result.
        apicall.setProcessor(function(data) {
          response.success[key] = data;
          return response;
        }).done();
      }

      return apicall;
    }
function ( key , options ) { options = opts ( this , options ) ; var response = { success : { } } , query ; if ( options . filename ) { query = { force_download : true , apikey : options . apikey , session_token : options . session_token , filename : options . filename } } var apicall = new APICall ( { action : 'binary/' + key , type : 'GET' , later : true , encoding : 'binary' , options : options , query : query } ) ; // Download file directly to computer if given a filename. if ( options . filename ) { if ( isNode ) { apicall . setProcessor ( function ( data ) { response . success [ key ] = fs . writeFileSync ( options . filename , data , 'binary' ) ; return response ; } ) . done ( ) ; } else { function detach ( ) { if ( iframe . parentNode ) document . body . removeChild ( iframe ) ; } var iframe = document . createElement ( 'iframe' ) ; iframe . style . display = 'none' ; document . body . appendChild ( iframe ) ; setTimeout ( function ( ) { iframe . src = apicall . url ; } , 25 ) ; iframe . onload = function ( ) { clearTimeout ( detach . timer ) ; detach . timer = setTimeout ( detach , 5000 ) ; } ; detach . timer = setTimeout ( detach , 60000 ) ; response . success [ key ] = iframe ; } apicall . done ( response ) ; } else if ( options . mode === 'buffer' && ( ArrayBuffer || Buffer ) ) { apicall . setProcessor ( function ( data ) { var buffer ; if ( Buffer ) { buffer = new Buffer ( data , 'binary' ) ; } else { buffer = new ArrayBuffer ( data . length ) ; var charView = new Uint8Array ( buffer ) ; for ( var i = 0 ; i < data . length ; ++ i ) { charView [ i ] = data [ i ] & 0xFF ; } } response . success [ key ] = buffer ; return response ; } ) . done ( ) ; } else { // Raw data return. Do not attempt to process the result. apicall . setProcessor ( function ( data ) { response . success [ key ] = data ; return response ; } ) . done ( ) ; } return apicall ; }
Download a file stored in CloudMine.
@param {string} key The binary file's object key.
@param {object} [options] Override defaults set on WebService. See WebService constructor for parameters.
@config {string} [filename] If present, the file will be downloaded directly to the computer with the
filename given. This does not validate the filename given!
@config {string} [mode] If buffer, automatically move returning data to either an ArrayBuffer or Buffer
if supported. Otherwise the result will be a standard string.
@return {APICall} An APICall instance for the web service request used to attach events.
Download a file stored in CloudMine .