Javascript downloading PDF from personal GoogleDrive

38 Views Asked by At

I try to load PDF from GoogleDrive like the following:

    function getConfigFile() {
        const fileAddress = 'https://drive.google.com/uc?id=15USHSjPl2kOjUL7WReHgFiwFVEUXJtqo';
        const requestInit = {
            'headers' : {
                'Access-Control-Allow-Origin' : '*'
            },
            'mode' : 'cors',
            'method' : 'GET'
        };

        fetch(fileAddress, requestInit).then(res => console.log(res)).catch(er => console.log(er));
    }

Unfortunately I receive error message:

Access to fetch at 'https://drive.google.com/uc?id=15USHSjPl2kOjUL7WReHgFiwFVEUXJtqo' from origin 'http://localhost:63342' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Problem occurs no matter if I try to fetch data from localhost or GitHub Pages. Here is the page itself if You want to have full access to the code:

https://testaccountforkotek.github.io/html/calendar.html

I tried to modify the request header in many ways like null or origin instead of * and I've read many threads associated with similar issues but still couldn't find the right answer.

ideally I'd like to receive the file and be able to operate on it further in JS file.

Thank You in advance!

0

There are 0 best solutions below