Skip to content

Commit 228ae69

Browse files
authored
deprecate(filesystem): deprecate downloadFile and add migration steps for file transfer plugin (#2360)
1 parent 10cf0ed commit 228ae69

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

filesystem/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,64 @@ For detailed steps on how to do this, please see the [Capacitor Docs](https://ca
4242
</plist>
4343
```
4444

45+
## Migrating from downloadFile to File Transfer plugin
46+
47+
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.
48+
49+
### Installing the File Transfer plugin
50+
51+
```bash
52+
npm install @capacitor/file-transfer
53+
npx cap sync
54+
```
55+
56+
### Migration example
57+
58+
Before (using Filesystem plugin):
59+
60+
```typescript
61+
import { Filesystem, Directory } from '@capacitor/filesystem';
62+
63+
await Filesystem.downloadFile({
64+
url: 'https://example.com/file.pdf',
65+
path: 'downloaded-file.pdf',
66+
directory: Directory.Documents,
67+
progress: true
68+
});
69+
70+
// Progress events
71+
Filesystem.addListener('progress', (progress) => {
72+
console.log(`Downloaded ${progress.bytes} of ${progress.contentLength}`);
73+
});
74+
```
75+
76+
After (using File Transfer plugin):
77+
78+
```typescript
79+
import { FileTransfer } from '@capacitor/file-transfer';
80+
import { Filesystem, Directory } from '@capacitor/filesystem';
81+
82+
// First get the full file path using Filesystem
83+
const fileInfo = await Filesystem.getUri({
84+
directory: Directory.Documents,
85+
path: 'downloaded-file.pdf'
86+
});
87+
88+
// Then use the FileTransfer plugin to download
89+
await FileTransfer.downloadFile({
90+
url: 'https://example.com/file.pdf',
91+
path: fileInfo.uri,
92+
progress: true
93+
});
94+
95+
// Progress events
96+
FileTransfer.addListener('progress', (progress) => {
97+
console.log(`Downloaded ${progress.bytes} of ${progress.contentLength}`);
98+
});
99+
```
100+
101+
The File Transfer plugin offers improved reliability, better error handling with specific error codes, and also adds upload functionality.
102+
45103
## iOS
46104

47105
To have files appear in the Files app, you must also set the following keys to `YES` in `Info.plist`:

filesystem/src/definitions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ export interface DownloadFileOptions extends HttpOptions {
486486
/**
487487
* The path the downloaded file should be moved to.
488488
*
489+
* @deprecated Use @capacitor/file-transfer instead.
489490
* @since 5.1.0
490491
*/
491492
path: string;
@@ -494,6 +495,7 @@ export interface DownloadFileOptions extends HttpOptions {
494495
* If this option is used, filePath can be a relative path rather than absolute.
495496
* The default is the `DATA` directory.
496497
*
498+
* @deprecated Use @capacitor/file-transfer instead.
497499
* @since 5.1.0
498500
*/
499501
directory?: Directory;
@@ -502,13 +504,15 @@ export interface DownloadFileOptions extends HttpOptions {
502504
* If this option is used, progress event should be dispatched on every chunk received.
503505
* Chunks are throttled to every 100ms on Android/iOS to avoid slowdowns.
504506
*
507+
* @deprecated Use @capacitor/file-transfer instead.
505508
* @since 5.1.0
506509
*/
507510
progress?: boolean;
508511
/**
509512
* Whether to create any missing parent directories.
510513
*
511514
* @default false
515+
* @deprecated Use @capacitor/file-transfer instead.
512516
* @since 5.1.2
513517
*/
514518
recursive?: boolean;
@@ -518,13 +522,15 @@ export interface DownloadFileResult {
518522
/**
519523
* The path the file was downloaded to.
520524
*
525+
* @deprecated Use @capacitor/file-transfer instead.
521526
* @since 5.1.0
522527
*/
523528
path?: string;
524529
/**
525530
* The blob data of the downloaded file.
526531
* This is only available on web.
527532
*
533+
* @deprecated Use @capacitor/file-transfer instead.
528534
* @since 5.1.0
529535
*/
530536
blob?: Blob;
@@ -533,18 +539,21 @@ export interface ProgressStatus {
533539
/**
534540
* The url of the file being downloaded.
535541
*
542+
* @deprecated Use @capacitor/file-transfer instead.
536543
* @since 5.1.0
537544
*/
538545
url: string;
539546
/**
540547
* The number of bytes downloaded so far.
541548
*
549+
* @deprecated Use @capacitor/file-transfer instead.
542550
* @since 5.1.0
543551
*/
544552
bytes: number;
545553
/**
546554
* The total number of bytes to download for this file.
547555
*
556+
* @deprecated Use @capacitor/file-transfer instead.
548557
* @since 5.1.0
549558
*/
550559
contentLength: number;
@@ -553,6 +562,7 @@ export interface ProgressStatus {
553562
/**
554563
* A listener function that receives progress events.
555564
*
565+
* @deprecated Use @capacitor/file-transfer instead.
556566
* @since 5.1.0
557567
*/
558568
export type ProgressListener = (progress: ProgressStatus) => void;
@@ -656,13 +666,15 @@ export interface FilesystemPlugin {
656666
/**
657667
* Perform a http request to a server and download the file to the specified destination.
658668
*
669+
* @deprecated Use @capacitor/file-transfer plugin instead.
659670
* @since 5.1.0
660671
*/
661672
downloadFile(options: DownloadFileOptions): Promise<DownloadFileResult>;
662673

663674
/**
664675
* Add a listener to file download progress events.
665676
*
677+
* @deprecated Use @capacitor/file-transfer plugin instead.
666678
* @since 5.1.0
667679
*/
668680
addListener(
@@ -672,6 +684,7 @@ export interface FilesystemPlugin {
672684
/**
673685
* Remove all listeners for this plugin.
674686
*
687+
* @deprecated Use @capacitor/file-transfer plugin instead.
675688
* @since 5.2.0
676689
*/
677690
removeAllListeners(): Promise<void>;

0 commit comments

Comments
 (0)