base64 file to be downloaded in capacitor iOS and Android

Discussão em 'Angular' iniciado por user1673892, Janeiro 17, 2025.

  1. user1673892

    user1673892 Guest

    I've an app made in angular and I'm packaging the app with capacitor for both iOS and Android. The app contains attachments which I request from back end and the result is base64 string. I manage to download the file without issues in Web, but the files are not downloadable in mobile version. Here's the download code.

    <div *ngFor="let attachment of attachmentsInput, let i = index">
    <div class="row pl-1 pr-1">
    <div class="col-lg-7">
    <a role="button" (click)="downloadFile(i)" class="hover">

    <span class="hover">{{attachment.name}}</span>
    </a>
    <a style="display: none;" id="downloadLinkId+{{i}}" [href]="attachmentsInput.toBeDownloaded" [download]="attachmentsInput.name"></a>
    </div>

    </div>
    </div>


    Download file code:

    async downloadFile(index) {
    this.attachmentsInput[index].toBeDownloaded = this.sanitizer.bypassSecurityTrustResourceUrl('data:image/jpg;base64,' + this.attachmentsInput[index].content);


    if (this.attachmentsInput[index].toBeDownloaded)
    document.getElementById('downloadLinkId+' + index).click();
    }


    Is there a problem in using document.getElementById ?

    Continue reading...

Compartilhe esta Página