0

I am just trying to implement Secured Upload functionality. Instead of asking user to select a file to upload, I have a textarea where user can paste the contents. I will parse it in JS.

I want to limit based on size not based on number of character. If it is number of charatcters, then I can easily implement it in JS

Doubts

1) Is it safe to limit data based on size?

2) I am new to JS. In C, One char is one byte. So I can calculate size easily. In JS, How can I do that?

3) If JS is also same as C style sizing, then does it browser dependent?

Any suggestions?

I am not interested in max length property of text area.

SIZE

I mean size by kilo bytes, mega bytes,..

Gibbs
  • 21,904
  • 13
  • 74
  • 138

1 Answers1

0

This should produce approximately the same number although file upload is including file details and text upload only contains the file contents.

<script>
function test() {
    console.log(document.getElementById('file' ).files[0 ].size);
    console.log(document.getElementById('text').value.length);
}
</script>
<input id="file" type="file" />
<br/>
<input type="text" id="text" />
<br/>
<button onclick="test();">test</button>
x13
  • 2,179
  • 1
  • 11
  • 27