Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions filesystem/README.md
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good!

We didn't add this in the context of the filesystem, but could we do changes that we did for geolocation in this PR as well? https://github.com/ionic-team/capacitor-plugins/pull/2304/files

Or do you prefer to open a separate PR for that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should be a separate PR so we can also include the File Viewer plugin. What are your thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure fair enough!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other filesystem PR: #2368

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,64 @@ For detailed steps on how to do this, please see the [Capacitor Docs](https://ca
</plist>
```

## Migrating from downloadFile to File Transfer plugin

As of version 7.1.0, the `downloadFile` functionality in the Filesystem plugin has been deprecated in favor of the new [@capacitor/file-transfer](https://capacitorjs.com/docs/apis/file-transfer) plugin.

### Installing the File Transfer plugin

```bash
npm install @capacitor/file-transfer
npx cap sync
```

### Migration example

Before (using Filesystem plugin):

```typescript
import { Filesystem, Directory } from '@capacitor/filesystem';

await Filesystem.downloadFile({
url: 'https://example.com/file.pdf',
path: 'downloaded-file.pdf',
directory: Directory.Documents,
progress: true
});

// Progress events
Filesystem.addListener('progress', (progress) => {
console.log(`Downloaded ${progress.bytes} of ${progress.contentLength}`);
});
```

After (using File Transfer plugin):

```typescript
import { FileTransfer } from '@capacitor/file-transfer';
import { Filesystem, Directory } from '@capacitor/filesystem';

// First get the full file path using Filesystem
const fileInfo = await Filesystem.getUri({
directory: Directory.Documents,
path: 'downloaded-file.pdf'
});

// Then use the FileTransfer plugin to download
await FileTransfer.downloadFile({
url: 'https://example.com/file.pdf',
path: fileInfo.uri,
progress: true
});

// Progress events
FileTransfer.addListener('progress', (progress) => {
console.log(`Downloaded ${progress.bytes} of ${progress.contentLength}`);
});
```

The File Transfer plugin offers improved reliability, better error handling with specific error codes, and also adds upload functionality.

## iOS

To have files appear in the Files app, you must also set the following keys to `YES` in `Info.plist`:
Expand Down
13 changes: 13 additions & 0 deletions filesystem/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ export interface DownloadFileOptions extends HttpOptions {
/**
* The path the downloaded file should be moved to.
*
* @deprecated Use @capacitor/file-transfer instead.
* @since 5.1.0
*/
path: string;
Expand All @@ -494,6 +495,7 @@ export interface DownloadFileOptions extends HttpOptions {
* If this option is used, filePath can be a relative path rather than absolute.
* The default is the `DATA` directory.
*
* @deprecated Use @capacitor/file-transfer instead.
* @since 5.1.0
*/
directory?: Directory;
Expand All @@ -502,13 +504,15 @@ export interface DownloadFileOptions extends HttpOptions {
* If this option is used, progress event should be dispatched on every chunk received.
* Chunks are throttled to every 100ms on Android/iOS to avoid slowdowns.
*
* @deprecated Use @capacitor/file-transfer instead.
* @since 5.1.0
*/
progress?: boolean;
/**
* Whether to create any missing parent directories.
*
* @default false
* @deprecated Use @capacitor/file-transfer instead.
* @since 5.1.2
*/
recursive?: boolean;
Expand All @@ -518,13 +522,15 @@ export interface DownloadFileResult {
/**
* The path the file was downloaded to.
*
* @deprecated Use @capacitor/file-transfer instead.
* @since 5.1.0
*/
path?: string;
/**
* The blob data of the downloaded file.
* This is only available on web.
*
* @deprecated Use @capacitor/file-transfer instead.
* @since 5.1.0
*/
blob?: Blob;
Expand All @@ -533,18 +539,21 @@ export interface ProgressStatus {
/**
* The url of the file being downloaded.
*
* @deprecated Use @capacitor/file-transfer instead.
* @since 5.1.0
*/
url: string;
/**
* The number of bytes downloaded so far.
*
* @deprecated Use @capacitor/file-transfer instead.
* @since 5.1.0
*/
bytes: number;
/**
* The total number of bytes to download for this file.
*
* @deprecated Use @capacitor/file-transfer instead.
* @since 5.1.0
*/
contentLength: number;
Expand All @@ -553,6 +562,7 @@ export interface ProgressStatus {
/**
* A listener function that receives progress events.
*
* @deprecated Use @capacitor/file-transfer instead.
* @since 5.1.0
*/
export type ProgressListener = (progress: ProgressStatus) => void;
Expand Down Expand Up @@ -656,13 +666,15 @@ export interface FilesystemPlugin {
/**
* Perform a http request to a server and download the file to the specified destination.
*
* @deprecated Use @capacitor/file-transfer plugin instead.
* @since 5.1.0
*/
downloadFile(options: DownloadFileOptions): Promise<DownloadFileResult>;

/**
* Add a listener to file download progress events.
*
* @deprecated Use @capacitor/file-transfer plugin instead.
* @since 5.1.0
*/
addListener(
Expand All @@ -672,6 +684,7 @@ export interface FilesystemPlugin {
/**
* Remove all listeners for this plugin.
*
* @deprecated Use @capacitor/file-transfer plugin instead.
* @since 5.2.0
*/
removeAllListeners(): Promise<void>;
Expand Down