How can I force the button to give the client a file (local) via js

Because I can't use the <a href="..."> -> server generates 404 error

  • do you understand English? stackoverflow.com/questions/3749231/… but even there you need to set the correct url, so you probably will have to figure out the 404 error - sam3434
  • 404 because there is no file along this path .... but you can always write a <a href="/path/to/your/file.ext">файл</a> and it will all be downloaded .. for example: codepen.io/ anon / pen / zrEzPy - Alexey Shimansky
  • one
    and you may also need this piece of code: data=new Blob(["\ufeff",[data]],{type:' _myme type_'}); var file=window.URL.createObjectURL(data); data=new Blob(["\ufeff",[data]],{type:' _myme type_'}); var file=window.URL.createObjectURL(data); then the contents of the file can be substituted as href into the link to the created file, add the attribute from the previous comment there, and voila - the file can be made directly in the browser on js and sent for download using html. - Darth
  • the client needs to download an apk-file from the server - Микола Кікець

3 answers 3

404 means that there is nothing on this link, try to check the correctness of the address, as for me it’s already reinventing the wheel via js

    As far as I understand it is a local file on a computer with a browser. Historically, the file: // protocol was used for this, but if the page is open from the server (via http), then for security it will not allow such a transition.

    code

     <a href="" onclick="location.href='file:///d:\\t.txt'; return false;">test</a> 

    works for example in chrome, if the file itself, which contains it, is also located locally. for Ineta, you need to play with the security level for the site and there may be a different approach to interpretation in different browsers. but without security settings will not work exactly. so for the "public" option will not work.

      Can you clarify some nuances, where is the page that you opened? it is on the server or you have it locally, because you are saying to give it to the client - it means that the site is on the server, and you are trying to give the file that you have locally. not affiliated with the server. Actually, therefore, it gives 404 error

      Maybe I misunderstood your description?