@grabjs/superapp-sdk
    Preparing search index...

    Class FileModule

    SDK module for downloading files to the user's device via JSBridge.

    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.

    ES Module:

    import { FileModule } from '@grabjs/superapp-sdk';
    const fileModule = new FileModule();

    CDN (UMD):

    <script src="https://cdn.jsdelivr.net/npm/@grabjs/superapp-sdk@x.y.z/dist/index.js"></script>
    <script>
    const fileModule = new SuperAppSDK.FileModule();
    </script>

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Downloads a file through JSBridge.

      Parameters

      Returns Promise<DownloadFileResponse>

      This method can return the following status_code values:

      • 204 (No Content): File downloaded successfully.
      • 400 (Bad Request): Invalid request parameters.
      • 500 (Internal Server Error): An unexpected error occurred.
      • 501 (Not Implemented): Requires Grab app environment.
      import { FileModule, isSuccess, isError } 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 (isError(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }