How to upload a file using javascript?

Manjeet Kumar Nai picture Manjeet Kumar Nai · Jun 26, 2018 · Viewed 25.7k times · Source

I want to create an uploader with js. Can anyone help me how to upload a file using javascript?

Answer

Firemen26 picture Firemen26 · Jun 26, 2018

You can use html5 file type like this:

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

You file will be in value:

var myUploadedFile = document.getElementById("myFile").files[0];

For more information see https://www.w3schools.com/jsref/dom_obj_fileupload.asp

and see example here: https://www.script-tutorials.com/pure-html5-file-upload/