lib/client.js
function(file, callback) {
        if (isBrowser && file instanceof window.File) {
            // Browser File instance
            return this.addImageFromBuffer(file, callback);
        }

        // File on filesystem. Note: the reason why we need the size of the file
        // is because of reverse proxies like Varnish which doesn't handle chunked
        // Transfer-Encoding properly - instead we need to explicitly pass the
        // content length so it knows not to terminate the HTTP connection
        readers.getLengthOfFile(file, function(err, fileSize) {
            if (err) {
                return callback(err);
            }

            readers.createReadStream(file).pipe(request({
                method: 'POST',
                uri: this.getSignedResourceUrl('POST', this.getImagesUrl()),
                json: true,
                headers: {
                    'Accept': 'application/json',
                    'User-Agent': 'imboclient-js',
                    'Content-Length': fileSize
                },
                onComplete: function(addErr, res, body) {
                    callback(addErr, body ? body.imageIdentifier : null, body, res);
                }
            }));
        }.bind(this));

        return this;
    }
function(file, callback) {
        if (isBrowser && file instanceof window.File) {
            // Browser File instance
            return this.addImageFromBuffer(file, callback);
        }

        // File on filesystem. Note: the reason why we need the size of the file
        // is because of reverse proxies like Varnish which doesn't handle chunked
        // Transfer-Encoding properly - instead we need to explicitly pass the
        // content length so it knows not to terminate the HTTP connection
        readers.getLengthOfFile(file, function(err, fileSize) {
            if (err) {
                return callback(err);
            }

            readers.createReadStream(file).pipe(request({
                method: 'POST',
                uri: this.getSignedResourceUrl('POST', this.getImagesUrl()),
                json: true,
                headers: {
                    'Accept': 'application/json',
                    'User-Agent': 'imboclient-js',
                    'Content-Length': fileSize
                },
                onComplete: function(addErr, res, body) {
                    callback(addErr, body ? body.imageIdentifier : null, body, res);
                }
            }));
        }.bind(this));

        return this;
    }
function ( file , callback ) { if ( isBrowser && file instanceof window . File ) { // Browser File instance return this . addImageFromBuffer ( file , callback ) ; } // File on filesystem. Note: the reason why we need the size of the file // is because of reverse proxies like Varnish which doesn't handle chunked // Transfer-Encoding properly - instead we need to explicitly pass the // content length so it knows not to terminate the HTTP connection readers . getLengthOfFile ( file , function ( err , fileSize ) { if ( err ) { return callback ( err ) ; } readers . createReadStream ( file ) . pipe ( request ( { method : 'POST' , uri : this . getSignedResourceUrl ( 'POST' , this . getImagesUrl ( ) ) , json : true , headers : { 'Accept' : 'application/json' , 'User-Agent' : 'imboclient-js' , 'Content-Length' : fileSize } , onComplete : function ( addErr , res , body ) { callback ( addErr , body ? body . imageIdentifier : null , body , res ) ; } } ) ) ; } . bind ( this ) ) ; return this ; }
Add a new image to the server from a local file

@param {String|File} file     - Path to the local image, or an instance of File
@param {Function}    callback - Function to call when image has been uploaded
@return {ImboClient}
Add a new image to the server from a local file