FileReader
FileReader copied to clipboard
Syntax error when using readAsText
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)
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?
It might also be related to issue #2... See resolution.
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!
how did you get the file?
reader.readAsText(file, 'UTF-8')
Thank you