5

I am following Html5rocks tutorial

http://www.html5rocks.com/en/tutorials/file/dndfiles/

and I am trying to use readAsArrayBuffer instead of readAsBinaryString in slicing a file example (because I want to read gif header to find file resolution). But I am stuck because evt.target.result (while using readAsBinaryString it is a string)

any ideas?

EDIT : Code

reader.onloadend = function(evt) 

{

  if (evt.target.readyState == FileReader.DONE) { // DONE == 2
    document.getElementById('byte_content').textContent = evt.target.result;
    console.log(evt.target.result.byteLenght)
    document.getElementById('byte_range').textContent = 
        ['Read bytes: ', start + 1, ' - ', stop + 1,
         ' of ', file.size, ' byte file'].join('');
  }
};

if (file.webkitSlice) {
  var blob = file.webkitSlice(start, stop + 1);
} else if (file.mozSlice) {
  var blob = file.mozSlice(start, stop + 1);
}
reader.readAsArrayBuffer(blob);
}

so in Firefox 13 I get on screen : [object ArrayBuffer]

and on console log : undefined

while in Chromium 18 I get on console : Uncaught TypeError: Cannot read property 'byteLenght' of null

4
  • 1
    Where exactely are you stuck? this is the base code. Now, what are your modifications, what did you expect and what goes wrong? Commented Jun 18, 2012 at 20:46
  • @RobW I changed reader.readAsBinaryString(blob); to eader.readAsArrayBuffer(blob) and I was expecting to get ArrayBufferbut I get null. Commented Jun 18, 2012 at 20:51
  • 1
    Can't reproduce in Chromium 18: jsfiddle.net/XDbnJ I see [object arrayBuffer]. Include your code in the question, including details about your browser and your expectations. Commented Jun 18, 2012 at 20:57
  • I can still not reproduce the error: jsfiddle.net/XDbnJ/1. Also, byteLength has to be spelled with th, not ht. Post a full demo using jsfiddle.net whihc shows your problem. Commented Jun 18, 2012 at 22:01

1 Answer 1

5

There is a typing mistake in:

console.log(evt.target.result.byteLenght)

byteLenght should be byteLength

Sign up to request clarification or add additional context in comments.

1 Comment

I already mentioned that in the comments. This is not the cause of the problem though: This would just log undefined, and not throw a TypeError.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.