Angular Frontend Cors

Discussão em 'Angular' iniciado por adem mrid, Novembro 13, 2024.

  1. adem mrid

    adem mrid Guest

    i want to upload xlsx file from google drive or any other website and opened it in my application(x-data-spreadsheet). the issue is when i try to upload the file i get error cors :

    "Access to fetch at 'https://drive.google.com/uc?export=view&id=1T-gTh7BpKf2hLMhZOq_lwvHTgcw80hxI' from origin 'http://localhost:4203' has been blocked by CORS policy: 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."

    this is my code in the frontend ts file : loadExcelFile() {

    const excelFileUrl = "https://drive.google.com/uc?export=view&id=1T-gTh7BpKf2hLMhZOq_lwvHTgcw80hxI"; // Replace with actual URL
    fetch(excelFileUrl)
    .then(response => response.arrayBuffer())
    .then(data => {
    const workbook = XLSX.read(data, { type: 'array' });
    const sheetName = workbook.SheetNames[0];
    const worksheet = workbook.Sheets[sheetName];
    const json = XLSX.utils.sheet_to_json(worksheet);

    console.log("LoadExcel from URL :" ,json); // Output parsed data to the console (or bind it to a table in the UI)
    this.dataLoad = json;
    const data55 = this.exportToExcel();
    const data555 = this.gridData_workbook_to(data55);
    this.spreadsheet.loadData(data555);

    });


    i tried proxy config with both names localhost and googledrive or the name of any website but nothing happen }

    Continue reading...

Compartilhe esta Página