apache / apache/cordova-plugin-file

Issue with file download on iOS

Open
#623 4 comments 0 reactions 0 assignees View on GitHub
info-needed
Dominant language
JavaScript
Stars
744
Forks
754
Avg merge
3d 4h
Merged PRs (30d)
1

Description

# Bug Report

## Problem
I'm encountering an issue with the cordova-plugin-file plugin in iOS when trying to download and save a PDF file from an API response. The plugin seems to be working fine in Android, but I'm facing difficulties in iOS.

### What is expected to happen?
The PDF file should be successfully downloaded and saved to the device's filesystem in iOS, similar to how it's functioning in Android.

### What does actually happen?
Code runs successfully and falls under the success block and even present the toast of 'File downloaded successfully.' But file is not downloaded on device.

## Information

### Command or Code

```
downloadPdfMobile(base64Data, fileName) {
const folderPath = this.platform.is('android')
? this.file.externalRootDirectory + 'Download/'
: this.file.documentsDirectory;

console.log(folderPath, 'FOLDERPATH');

// Convert base64 to Blob
const byteCharacters = atob(base64Data);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], { type: 'application/pdf' });

// Write the file
this.file
.writeFile(folderPath, fileName, blob, {
replace: true,
})
.then(() => {
this.presentToast('File downloaded successfully.');
console.log('File downloaded successfully.');
})
.catch((error) => {
this.presentToast('Error while downloading the file:');
console.error('Error while downloading the file:', error);
});
}
```

### Environment, Platform, Device

### Version information

Cordova Version: 12.0.0

## Checklist

- [x] I included all the necessary information above
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version

Contributor guide

Open the contributing guide

Research direction

Start by reproducing downloadPdfMobile with cordova-plugin-file on iOS, focusing on the documentsDirectory path and the writeFile success callback. Verify where the PDF is saved and whether it can be found or opened; done means the downloaded PDF is present on the iOS device, with the relevant environment and device details recorded.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.