reactjs - How to upload a file from local in React? -


i tried using filereader html5 api, in react needs npm module , corresponding npm module filereader isn't working , showing error after file upload. without doing require('filereader'), webpack shows error.

with npm module filereader shows: "uncaught error: cannot read file: {"preview":"blob:http%3a//dev.myntra.com%3a3000/cfb8a917-b3df-46b2-b055-21da34f253f2"}" can use other npm module kind of file or there way can use filereader api directly react? code:

{ ondrop(files) {   this.setstate({     files: files    });   console.log(files[0]);   var reader = new filereader();    var contents;     reader.onload = function(event) {       contents = this.result;       console.log(contents);        $.ajax({       type: 'post',       url: '/api/csv',       async: true,       data: json,       crossdomain: true,       contenttype: "application/json; charset=utf-8",       processdata: false,       timeout:5000,       success: function(response){         console.log("success");       },       error: function(jqxhr, textstatus){         console.log("error");         }                    });     }         reader.readastext(files[0],'utf8');    }     render() {   return (     <div>     <dropzone ondrop={this.ondrop}>     <div>try dropping files here, or click select files upload.</div>     </dropzone>     </div>     ); } } 

the problem got solved using window.filereader, through can access html5's filereader api without using npm package.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -