How to use the enketo-core/src/js/utils.getFilename function in enketo-core

To help you get started, we’ve selected a few enketo-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kobotoolbox / enketo-express / public / js / src / module / file-manager.js View on Github external
if ( this.type === 'file' ) {
            file = this.files[ 0 ]; // Why doesn't this fail for empty file inputs?
        } else if ( this.value ) {
            canvas = $( this ).closest( '.question' )[ 0 ].querySelector( '.draw-widget canvas' );
            if ( canvas && !URL_RE.test( this.value ) ) {
                // TODO: In the future, we could do canvas.toBlob()
                file = utils.dataUriToBlobSync( canvas.toDataURL() );
                file.name = this.value;
            }
        }
        if ( file && file.name ) {
            // Correct file names by adding a unique-ish postfix
            // First create a clone, because the name property is immutable
            // TODO: in the future, when browser support increase we can invoke
            // the File constructor to do this.
            newFilename = getFilename( file, this.dataset.filenamePostfix );
            // If file is resized, get Blob representation of data URI
            if ( this.dataset.resized && this.dataset.resizedDataURI ) {
                file = utils.dataUriToBlobSync( this.dataset.resizedDataURI );
            }
            file = new Blob( [ file ], {
                type: file.type
            } );
            file.name = newFilename;
            files.push( file );
        }
    } );