Search code examples
javascriptextjssencha-touch-2

how to save a file from browser to local directory by java script?


I have to save a pdf file(which opens inside the browser) to the local directory on the same machine.

Any idea ,How to do it by java script or ExtJS?


Solution

  • Either politely inform the user of the "right click » save as..." functionality - or serve the PDF with the following HTTP headers:

    Content-disposition: attachment; filename=<FILENAME>.pdf
    Content-type: application/octet-stream
    

    Which implies that, (source: rfc2616)

    ... the user agent should not display the response, but directly enter a `save response as...' dialog.

    Beyond this you have no say in where a file should be saved for security reasons.