Downloading pdf file which is not reachable over http

In some places I have some files which can’t be found from outside but I would like to offer them to download.

could you please give me a hint how to manage this in the way of using pdfviewer I can download but now I would like to download without viewing first.

Thanks a lot

Michael

Hello @Michael,

If I understood you correcty,

To display the PDF file that is already loaded to the client-side, you need to use parse method.

In the case of a Base64 string, PDF viewer expects the following syntax:

$$(“pdf”).parse({data:pdfData});

The following sample shows a common way to load client-side PDF file represented as Base64: Code Snippet

Also, please note that in Webix data components, load method is used to get the data from the remote resource. It expects an URL as a parameter invokes its own AJAX request to the specified source.

In case you need to upload files, Files are uploaded with the help of a dedicated UI component called uploader .

Please, check the snippet here: Code Snippet

There is a possibility to bind Uploader to any page element. In the example below, uploader is invisible and the download process is initiated by pressing the “Enter” key: Code Snippet

Thanks a lot, but I found another solution:

json object :

{
    download: (filename) =>{
        webix.ajax().response('arraybuffer').post('/documents/download', {filename:filename, path: 'your/absolute/server/path'}, function(){}).then(function(text){
            const blob = new Blob([text], { type: 'application/pdf' });
            const link = window.URL.createObjectURL(blob);
            let dllink = document.createElement('a');
            dllink.setAttribute('href',link);
            dllink.setAttribute('style', 'display:none');
            dllink.setAttribute('download',filename); // Added Line
            document.body.appendChild(dllink);
            dllink.click();
            URL.revokeObjectURL(link);
            document.body.removeChild(dllink);
        });
    },
}

in your DocumentsController:

    public function download(): void{
        $this->autoRender = false;
        $data = $this->request->getData();
        header('Content-Type: application/pdf');
        header('Content-Disposition: attachment; filename='.$data['filename']);
        readfile($data['path'].$data['filename']);
        exit();
    }

In my solution I can not use htt protocol cause file are not loadable/reachable via
https://somedomain/somepath/somefile.pdf

Maybe someone is interested and want to use it…

Michael