Downloads a file via the native bridge.
File information, including URL and target file name.
Download operation result.
Simple usage
import { FileModule, isSuccess, isErrorResponse } from '@grabjs/superapp-sdk';
// Initialize the file module
const file = new FileModule();
// Download the file
const response = await file.downloadFile({
fileUrl: 'https://example.com/report.pdf',
fileName: 'report.pdf',
});
// Handle the response
if (isSuccess(response)) {
console.log('File downloaded successfully');
} else if (isErrorResponse(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
JSBridge module for downloading files to the user's device.
Remarks
Initiates native file download handling in the Grab app using a file URL and file name. This code must run on the Grab SuperApp's WebView to function correctly.
Example
ES Module:
Example
CDN (UMD):