FileReader icon indicating copy to clipboard operation
FileReader copied to clipboard

Syntax error when using readAsText

Open dietervds opened this issue 12 years ago • 4 comments

First of all: thanks for an awesome polyfill, it saved my day :-)

When I attempt to call readAsText, both Chrome and Firefox return errors that I can't pinpoint. I've pasted the errors below. Safari doesn't give an error, but target.result is just undefined. When I use readAsDataUrl, it works fine.

Chrome error: Uncaught SyntaxError: Unexpected token ILLEGAL (filereader.jquery.js:256) window.FileReader._handleFlashEvent (filereader.jquery.js:256) window.FileAPIProxy.onFileReaderEvent (filereader.jquery.js:139) (anonymous function)

Firefox error: unterminated string literal var __flash_temp = "application/pdf\r\ninvoice.pdf\r\nYES\r\n%PDF-1.4\n%ª«¬\n4 ... (with an arrow pointing to the " before application/...)

(part of) the code:


            var sendData = function(event) {
                console.log(event)
                var filedata = event.target.result
                console.log(filedata)
            }

            var reader = new FileReader();
            reader.onload = sendData;
            reader.onerror = function(stuff) {
                console.log("error", stuff)
                console.log (stuff.getMessage())
            }
            reader.readAsText(file, 'UTF-8')
            //reader.readAsDataURL(file)

dietervds avatar Jul 04 '12 11:07 dietervds

Seems that your filename contains a character that is illegal as a javascript object attribute name. Could you please make a "console.log(FileAPIProxy.swfObject.result) just before the error is thrown?

AVapps avatar Jul 19 '12 18:07 AVapps

It might also be related to issue #2... See resolution.

AVapps avatar Jul 21 '12 10:07 AVapps

Thanks, will take a look when the opportunity presents itself to open the code again :-) Right now worked slightly around it. I'll keep you informed once I can!

dietervds avatar Jul 21 '12 10:07 dietervds

how did you get the file?

reader.readAsText(file, 'UTF-8')

Thank you

joanrm20 avatar Feb 13 '14 13:02 joanrm20