CORS (Cross-Origin Resource Sharing) issue in Ionic project

Discussão em 'Angular' iniciado por Pooja S G, Março 20, 2025.

  1. Pooja S G

    Pooja S G Guest

    I was trying to download a PDF or an image from the backend and share it directly via WhatsApp. but is showing CORS issue how to fix this issue, can some help me to fix

    async shareFiles() {
    try {
    const imageUrl =
    'https://lead247.in/images/floorplans/1632742852-1528349324-master-plan.jpg';

    // Fetch image data as BLOB
    const response = await Http.get({
    url: imageUrl,
    responseType: 'blob' // Important to get binary data
    });

    // Convert BLOB to Base64
    const reader = new FileReader();
    reader.onloadend = async () => {
    const base64Data = reader.result?.toString().split(',')[1];

    // Save Image to Device Storage
    await Filesystem.writeFile({
    path: 'downloaded-image.jpg',
    data: base64Data!,
    directory: Directory.Documents
    });

    console.log('Image downloaded successfully!');
    };

    reader.readAsDataURL(new Blob([response.data]));

    } catch (error) {
    console.error('Error downloading image:', error);
    }
    }

    <ion-button (click)="shareFiles()">
    Share
    </ion-button>


    this is my code ,when I click on share but need share pdf file rather link directly file as like how we share document in what's app but here it coming from backend api, not in local

    Continue reading...

Compartilhe esta Página