alpaylan/afetbilgi.com

Download as PDF butonu direkt indirse daha iyi olmaz mı siteye gitmek yerine?

alpaylan opened this issue · 3 comments

Download as PDF butonu direkt indirse daha iyi olmaz mı siteye gitmek yerine?

biraz baktım ben buna CORS'dan dolayı biraz sıkıntı, istersek yaparız da kısa vadede değmez gibi

cross-domain olduğu için <a href download> tagı çalışmıyor, axios'la cors'a takılmadan alabilirsek şunu gibi bir şey olabilir (denemedim)
import axios from "axios";

export const downloadPDF = async (lang: string) => {
  const response = await axios.get(`https://pdf.afetbilgi.com/${lang}`);
  const file = new Blob([response.data], { type: 'application/pdf' });
  const a = document.createElement("a");
  a.href = URL.createObjectURL(file);
  a.style.display = "none";

  a.download = `afetbilgi_${lang}.pdf`;
  document.body.appendChild(a);
  a.click();
};

cdn'e nasıl redirect ediyo bilmediğimden burda bırakıyorum
edit:
http response header'ına alttakini ekleyince de oluyomuş diye okudum şurda
Content-Disposition: attachment; filename=afetbilgi.pdf

AWS'den hallettim. CF cache resetlendiginde son kullaniciya yansir.
#183 closes this.