Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js json upload

function upload() {
    const input = document.createElement('input');
    input.style.visibility = 'hidden';
    input.type = 'file';
    input.onchange = e => { 
        // getting a hold of the file reference
        const file = e.target.files[0];
        // setting up the reader
        const reader = new FileReader();
        reader.readAsText(file,'UTF-8');
        // here we tell the reader what to do when it's done reading...
        reader.onload = readerEvent => {
            let content = readerEvent.target.result; // this is the content!
            try {
                // Try to read json
                // noinspection JSCheckFunctionSignatures
                objs = JSON.parse(content);
            } catch (e) {
                objs = {};
            }
        }
    }
    input.click();
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Make Array Consecutive javascript 
Javascript :: react input number 
Javascript :: mathjs get element from matrix 
Javascript :: node download s3 file 
Javascript :: vuejs watch sub property 
Javascript :: how to get sys time in js 
Javascript :: unable to resolve path to module eslint(import/no-unresolved) absoute path 
Javascript :: search string in file node 
Javascript :: upsert mongoose 
Javascript :: node js get file name without extension 
Javascript :: How to download files using axios 
Javascript :: add formdata to axios request in js 
Javascript :: js onchange paramteter sring 
Javascript :: how to remove first element of array javascript 
Javascript :: react fontawesome 
Javascript :: javascript convert date to yyyy-mm-dd 
Javascript :: js html play beep 
Javascript :: javascript regex vowel 
Javascript :: react create root 
Javascript :: react app.js 
Javascript :: ignore node_modules 
Javascript :: node.js read json file 
Javascript :: nodejs get response time 
Javascript :: npm fake server 
Javascript :: react native scrollview in modal 
Javascript :: how to get os information nodejs 
Javascript :: media query in react js 
Javascript :: How to include JSPs file from another folder 
Javascript :: click button when press enter javascript 
Javascript :: js sort string array 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =