Search code examples
javascriptjqueryapiform-data

How to append a specific file to FormData with Javascript?


I need to append a specific file to my FormData object using JavaScript.

var form = new FormData();
form.append("input", '{ ... some json ... }');
form.append("files", "/C:/My/Path/File.txt");

I dont want to select the file through a input button.

All examples that i founded do this:

var form = new FormData();
form.append("input", '{ ... some json ... }');
form.append("files", input.Files[0], "/C:/My/Path/File.txt");
        

So i think that i have to load that file into a blob or file object. But i dont get it.

Hoy can i do it? Thanks!


Solution

  • Acoording to @Andy comment and to this post https://stackoverflow.com/a/3014623/8037813, effectively it is not possible to do this by security issues.

    Dont lose your time trying to do it.

    Thanks.