uploadUserImage(userId, imageType, file) {

        if (!userId) {
            throw new Error("null userId");
        }

        if (!imageType) {
            throw new Error("null imageType");
        }

        if (!file) {
            throw new Error("File must be an image.");
        }

        if (file.type !== "image/png" && file.type !== "image/jpeg" && file.type !== "image/jpeg") {
            throw new Error("File must be an image.");
        }

        const instance = this;

        return new Promise((resolve, reject) => {

            const reader = new FileReader();

            reader.onerror = () => {
                reject();
            };

            reader.onabort = () => {
                reject();
            };

            // Closure to capture the file information.
            reader.onload = e => {

                // Split by a comma to remove the url: prefix
                const data = e.target.result.split(',')[1];

                const url = instance.getUrl(`Users/${userId}/Images/${imageType}`);

                instance.ajax({
                    type: "POST",
                    url,
                    data,
                    contentType: `image/${file.name.substring(file.name.lastIndexOf('.') + 1)}`
                }).then(resolve, reject);
            };

            // Read in the image file as a data URL.
            reader.readAsDataURL(file);
        });
    }
/**
     * Uploads a user image
     * @param {String} userId
     * @param {String} imageType The type of image to delete, based on the server-side ImageType enum.
     * @param {Object} file The file from the input element
     */
Uploads a user image
@param {String} userId
@param {String} imageType The type of image to delete, based on the server-side ImageType enum.
@param {Object} file The file from the input element
Uploads a user image @param { String } userId @param { String } imageType The type of image to delete based on the server - side ImageType enum . @param { Object } file The file from the input element
uploadUserImage(userId, imageType, file) {
        if (!userId) {
            throw new Error("null userId");
        }
        if (!imageType) {
            throw new Error("null imageType");
        }
        if (!file) {
            throw new Error("File must be an image.");
        }
        if (file.type !== "image/png" && file.type !== "image/jpeg" && file.type !== "image/jpeg") {
            throw new Error("File must be an image.");
        }
        const instance = this;
        return new Promise((resolve, reject) => {
            const reader = new FileReader();
            reader.onerror = () => {
                reject();
            };
            reader.onabort = () => {
                reject();
            };
            reader.onload = e => {
                const data = e.target.result.split(',')[1];
                const url = instance.getUrl(`Users/${userId}/Images/${imageType}`);
                instance.ajax({
                    type: "POST",
                    url,
                    data,
                    contentType: `image/${file.name.substring(file.name.lastIndexOf('.') + 1)}`
                }).then(resolve, reject);
            };
            reader.readAsDataURL(file);
        });
    }
uploadUserImage ( userId , imageType , file ) { if ( ! userId ) { throw new Error ( "null userId" ) ; } if ( ! imageType ) { throw new Error ( "null imageType" ) ; } if ( ! file ) { throw new Error ( "File must be an image." ) ; } if ( file . type !== "image/png" && file . type !== "image/jpeg" && file . type !== "image/jpeg" ) { throw new Error ( "File must be an image." ) ; } const instance = this ; return new Promise ( ( resolve , reject ) => { const reader = new FileReader ( ) ; reader . onerror = ( ) => { reject ( ) ; } ; reader . onabort = ( ) => { reject ( ) ; } ; reader . onload = e => { const data = e . target . result . split ( ',' ) [ 1 ] ; const url = instance . getUrl ( ` ${ userId } ${ imageType } ` ) ; instance . ajax ( { type : "POST" , url , data , contentType : ` ${ file . name . substring ( file . name . lastIndexOf ( '.' ) + 1 ) } ` } ) . then ( resolve , reject ) ; } ; reader . readAsDataURL ( file ) ; } ) ; }
Uploads a user image
 @param {String} userId
 @param {String} imageType The type of image to delete, based on the server-side ImageType enum.
Uploads a user image @param { String } userId @param { String } imageType The type of image to delete based on the server - side ImageType enum .
// Closure to capture the file information. // Split by a comma to remove the url: prefix // Read in the image file as a data URL.