DEV Community 👩‍💻👨‍💻

AndyBullet
AndyBullet

Posted on

Help me please: Auto-uploading file in an html input type="file"

Hi guys, I have a question.
I would like to write a javascript code that uploads a file in an input type="file" of my html page by its name or its path.
Is it possible?

Top comments (4)

Collapse
 
jordanfinners profile image
Jordan Finneran

Can I ask you to explain your use case a bit more?

Collapse
 
andybullet profile image
AndyBullet

I want to make an input button in html of file type, to upload a file. But I don't want to click the button and choose the file, I want to write the path of the file in javascript and upload it automatically.

Collapse
 
jordanfinners profile image
Jordan Finneran

No you can't automatically click and do the file upload in Javascript, because it doesn't have permissions to access your files. That button handles the communication between your application running inside a browser and the file system, you never have access to this for security purposes.

Collapse
 
jordanfinners profile image
Jordan Finneran

Not sure on what you're trying to achieve with this, but you might want to check out this File System API which might work for what you're trying to do.
web.dev/file-system-access/

Visualizing Promises and Async/Await 🤯

async await

☝️ Check out this all-time classic DEV post