Javascript - create text file on website

前端 未结 5 664
庸人自扰
庸人自扰 2021-01-29 07:39

So I have a web page, and I would like to programaticly create a text file (lets say it has the words \'hello, I am a text file\' in it) on a new directory on my website. The pr

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-29 08:05

    If, when you say "JavaScript", you're referring to a node.js application running on a server, then this is possible. It doesn't have to be node though; it could be a Django site, or an ASP.Net site, doesn't matter. You can't have JS code in the browser create files on your server... the JS in the browser is executing on a client machine, and doesn't have access to the server's file system.

    You could create an endpoint to which your clients could send requests that would initiate the creation of the file.

    You could also allow clients to PUT or POST files to your server, but again, this is something you control from the server side of the application. Your webpage (i.e., HTML file as you put it) cannot create files on the server itself. Your server allows clients to send it files in a specific manner, and the client must adhere to those rules.

提交回复
热议问题