Is there a JavaScript type that stores data from any file?

-1

Ex: In a form in an input field of file type in an html any user in my system appends a file. After pressing Submit I want the file to be kept in a JavaScript variable. Is there any kind of it? If not what do you advise me to do?

    
asked by anonymous 21.03.2018 / 00:19

2 answers

-2

You can do this with localStorage using API file .

Create a event handler for input file and save it on localStorage :

<input type="file" id="file">

<script>
var arq = document.body.querySelector("#file");

arq.addEventListener("change", function(){

   localStorage.setItem("arquivo",this.files[0].name);

});
</script>

When you want to call the file name, use:

localStorage.getItem("arquivo");
    
21.03.2018 / 01:06
-1

If you only want to create a variable and assign it document.getElementById('input').files (array of selected files), if you want only one file use .files[0]

JavaScript has the object File , it has the data of the file (size, last modification date, name, type ...) and Blob , in general this type can be used in any context of a% traditional%.

Law Plus

    
21.03.2018 / 00:52