简体   繁体   中英

ReactJs Download a file from local folder

I have this code :

var link= document.createElement("a");
link.setAttribute("download",name);
link.href=uri;
link.target="_blank";
document.body.appendChild(link);
link.click();
link.remove();

Here I am passing -

url ="M:/folderfname/filename.xlsx";
name = "filename.xlsx"

I am getting this error:

Not Allowed To Load Local Resource file://M:/folderfname/filename.xlsx

I am not getting how can I resolve this in react. Or is there any alternative to download file ?

Note : this is not about downloading a single file which I can import and download. FileName to download getting generated dynamically.

It is not possible to access the local file system in your browser app without explicit permission. One of the browser's primary functions is to prevent this.

You can take a look at the File System Access API for progress in this area. Alternatively, you can operate a web server on your device and communicate with it in your app, using it as a proxy to access the file system. Because you are already writing JavaScript, I suggest that you explore Deno and Node for the server approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM