Download Remote file and save in Document Storage: Error: NO_DATA

I need to download a document from a remote server and save it locally for offline consultation. I developed this code but I am getting error.

I read that Filesystem has downloadFile() but I don’t understand as use it. So I created custom method in order to download file, convert to blob and then save it using plugin.

 async downloadFile() {
    const url = 'https://calibre-ebook.com/downloads/demos/demo.docx';
    const filePath = 'demo.docx'; // Percorso locale dove salvare il file
  
    try {
      
      const response = await fetch(url, {
        mode: 'no-cors'
      });

      const blob = await response.blob();
      
      console.debug("BLOB:", blob);

      await Filesystem.writeFile({
        path: filePath,
        data: blob,
        directory: Directory.Documents,
        encoding: Encoding.UTF8 // Puoi scegliere l'encoding del file
      });
  
      console.log('File saved successfully');
      alert('File saved successfully');
    } catch (error) {
      console.error('Error occurred:', error);
      alert ("Error occurred");
    }
  }

Error Occurred:

Error: NO_DATA
    at returnResult ((index):956:32)
    at cap.fromNative ((index):938:17)
    at <anonymous>:1:18

Tested on Android Real Device.

Do I need to add any explicit permissions?

Thanks

Filesystem plugin doesn’t accept blob as data, it has to be a string or base64 encoded data

Solved

    const url = 'https://calibre-ebook.com/downloads/demos/demo.docx';

    let options = {
      url: url,
      path: '/demo.docx',
      directory: Directory.Documents,
      progress: true,
      recursive: true
    } as DownloadFileOptions;

    await Filesystem.downloadFile(options);

Not works on iOS platform