0

ERROR getting ::

Uncaught (in promise) TypeError: window.URL.createObjectURL is not a function at eval
unable to download pdf

My code:

axios({                   
  url: url,                    
  method: 'GET',                    
  responseType: 'blob',                    
  headers: {                        
    'Authorization': 'Bearer ' +localStorage.getItem('token'),                        
  }                    
}).then((response) => {
  const url = window.URL.createObjectURL(new Blob([response.data]));                    
  const link = document.createElement('a');                    
  link.href = url;                    
  link.setAttribute('download', 'file.pdf'); //or any other extension                    
  document.body.appendChild(link);                    
  link.click();                    
});

backend:

public function getPDF(Request $request) {        
    $pdf = App::make('dompdf.wrapper');
    $pdf->loadHTML('<h1><center>Test</center></h1>');        
    return $pdf->download('invoice.pdf');            
}
11
  • 1
    Browser and version please. You may be on an older version of chrome / ff / safari here. Commented Mar 8, 2019 at 5:26
  • Version 71.0.3578.98 (Official Build) (64-bit) chrome Commented Mar 8, 2019 at 5:36
  • Try console.log(window.URL) as the first line in your then() callback. What does that show in your console? Commented Mar 8, 2019 at 5:39
  • open your console and paste this:window.URL.createObjectURL(new Blob()); do you get the current URL as a blob? Commented Mar 8, 2019 at 5:44
  • 1
    Possible duplicate of Uncaught TypeError: URL is not a constructor in javascript Commented Mar 8, 2019 at 5:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.