Skip to content

Download File Component ​

The DownloadFileComponent enables downloading files from the web to the device's storage.

Basic Info ​

Description ​

This component allows users to download files (PDFs, images, documents) directly to the device's download folder, with progress tracking and completion callbacks.

How to Use ​

1. Web Implementation ​

javascript
import { useDownload } from '@bagisto-native/react';

const DownloadComponent = () => {
    const { downloadFile } = useDownload();

    const handleDownload = () => {
        downloadFile({
            url: "https://example.com/invoice.pdf",
            fileName: "invoice.pdf",
            onProgress: (progress) => {
                console.log("Download progress:", progress + "%");
            },
            onComplete: (filePath) => {
                console.log("Downloaded to:", filePath);
            },
            onError: (error) => {
                console.log("Download failed:", error);
            }
        });
    };

    return <button onClick={handleDownload}>Download Invoice</button>;
};

2. Native Side ​

kotlin
navigator.registerBridgeComponent("downloadFile", DownloadFileComponent(this))

API Reference ​

PropertyTypeRequiredDescription
urlStringYesURL to download
fileNameStringNoCustom file name
onProgressFunctionNoProgress callback (0-100)
onCompleteFunctionNoSuccess callback
onErrorFunctionNoError callback

Required Permissions ​

Add to AndroidManifest.xml:

xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Next Steps ​

Released under the MIT License.