index.js
function (file, options, callback) {
            var args = arguments,
                r,
                param,
                form,
                handler,
                params,
                retry = false,
                requestOptions = {
                    method: 'POST'
                };

            if (typeof file === 'string') {
                file = fs.createReadStream(file);
            }

            if (typeof options === 'function') {
                callback = options;
                params = {};
            } else {
                options = extend({}, options);
                params = extend({}, options.params);
                retry = options.retry;
            }

            retry = (retry === true) && function () {
                this.uploadFile.apply(this, args);
            }.bind(this);

            // filename is required for the form to work properly, so try to
            // figure out a name...
            if (!params.name) {
                params.name = determineFilename(file);
            }

            // if the file is a stream, we cannot retry
            if (retry && file.readable) {
                throw new Error('Retry option is not supported for streams.');
            }

            handler = createResponseHandler(callback, [200, 202], retry);

            form = new FormData();
            for (param in params) {
                if (params.hasOwnProperty(param)) {
                    form.append(param, params[param].toString());
                }
            }

            form.append('file', file, { filename: params.name });
            extend(true, requestOptions, {
                headers: form.getHeaders()
            });

            r = req(client.documentsUploadURL, requestOptions, handler);
            form.pipe(r);
            return r;
        }
function (file, options, callback) {
            var args = arguments,
                r,
                param,
                form,
                handler,
                params,
                retry = false,
                requestOptions = {
                    method: 'POST'
                };

            if (typeof file === 'string') {
                file = fs.createReadStream(file);
            }

            if (typeof options === 'function') {
                callback = options;
                params = {};
            } else {
                options = extend({}, options);
                params = extend({}, options.params);
                retry = options.retry;
            }

            retry = (retry === true) && function () {
                this.uploadFile.apply(this, args);
            }.bind(this);

            // filename is required for the form to work properly, so try to
            // figure out a name...
            if (!params.name) {
                params.name = determineFilename(file);
            }

            // if the file is a stream, we cannot retry
            if (retry && file.readable) {
                throw new Error('Retry option is not supported for streams.');
            }

            handler = createResponseHandler(callback, [200, 202], retry);

            form = new FormData();
            for (param in params) {
                if (params.hasOwnProperty(param)) {
                    form.append(param, params[param].toString());
                }
            }

            form.append('file', file, { filename: params.name });
            extend(true, requestOptions, {
                headers: form.getHeaders()
            });

            r = req(client.documentsUploadURL, requestOptions, handler);
            form.pipe(r);
            return r;
        }
function ( file , options , callback ) { var args = arguments , r , param , form , handler , params , retry = false , requestOptions = { method : 'POST' } ; if ( typeof file === 'string' ) { file = fs . createReadStream ( file ) ; } if ( typeof options === 'function' ) { callback = options ; params = { } ; } else { options = extend ( { } , options ) ; params = extend ( { } , options . params ) ; retry = options . retry ; } retry = ( retry === true ) && function ( ) { this . uploadFile . apply ( this , args ) ; } . bind ( this ) ; // filename is required for the form to work properly, so try to // figure out a name... if ( ! params . name ) { params . name = determineFilename ( file ) ; } // if the file is a stream, we cannot retry if ( retry && file . readable ) { throw new Error ( 'Retry option is not supported for streams.' ) ; } handler = createResponseHandler ( callback , [ 200 , 202 ] , retry ) ; form = new FormData ( ) ; for ( param in params ) { if ( params . hasOwnProperty ( param ) ) { form . append ( param , params [ param ] . toString ( ) ) ; } } form . append ( 'file' , file , { filename : params . name } ) ; extend ( true , requestOptions , { headers : form . getHeaders ( ) } ) ; r = req ( client . documentsUploadURL , requestOptions , handler ) ; form . pipe ( r ) ; return r ; }
Do a multipart upload from a file path or readable stream
@param   {String|Stream|Buffer}  file                        A path to a file to read, a readable stream, or a Buffer
@param   {Object}                [options]                   Upload options
@param   {boolean}               [options.retry]             Whether to retry the request after 'retry-after' seconds if the retry-after header is sent
@param   {Object}                [options.params]            Upload parameters
@param   {String}                [options.params.name]       The name of the file
@param   {String}                [options.params.thumbnails] Comma-separated list of thumbnail dimensions of the format {width}x{height} e.g. 128×128,256×256 – width can be between 16 and 1024, height between 16 and 768
@param   {Boolean}               [options.params.non_svg]    Whether to also create the non-svg version of the document
@param   {Function}              [callback]                  A callback to call with the response data (or error)
@returns {Request}
Do a multipart upload from a file path or readable stream