capacitor-community / sqlite

Community plugin for native & electron SQLite databases
MIT License
426 stars 104 forks source link

GetFromHTTPRequest not working #534

Closed rosostolato closed 3 weeks ago

rosostolato commented 1 month ago

Describe the bug The GetFromHTTPRequest method is not working on Android when you have a Firebase storage link, which contains query params. I guess it's an issue similar to this one https://github.com/jepiqueau/jeep-sqlite/issues/39.

Error: GetFromHTTPRequest: length=0; index=-3

To Reproduce Here is an example of one of my databases stored in my Firebase storage project: https://firebasestorage.googleapis.com/v0/b/ipmacae-app.appspot.com/o/bibles%2FNVI.zip?alt=media&token=3c035e3e-7a5e-4532-bbf2-4e93e5d69b61

To make jeepSqlite work, I need to add a final param called ext with the extension of the database. It works just fine on the web but doesn't work on Android and probably on iOS either.

  async loadDatabaseFromServer(
    database: string,
    url: string,
    ext: 'db' | 'zip',
  ): Promise<void> {
    let databases: string[] = [];
    try {
      const result = await this.sqliteConnection.getDatabaseList();
      databases = result.values ?? [];
    } catch {
      // do nothing
    }
    if (!databases.includes(`${database}SQLite.db`)) {
      await this.sqliteConnection.getFromHTTPRequest(
        `${url}&ext=.${ext}`,
        true,
      );
      const result = await this.sqliteConnection.getDatabaseList();
      databases = result.values ?? [];
    }
    await Toast.show({
      text: `Database ${database} loaded from server. ${databases.values}`,
      duration: 'long',
    });
  }

Expected behavior It should toast the success message.

Screenshots image

Smartphone (please complete the following information):

rosostolato commented 1 month ago

I found what the problem is, firebase returns a disposition with filename*=utf-8"{fileName}. I tried to fix it by signing the blob just like mentioned here but it still doesn't work.

If it's too overkill to handle this scenario on the plugin, I will try to move to another storage service, e.g. CloudFlare.

jepiqueau commented 1 month ago

@rosostolato i will have a look later to see if i can find a solution for it

jepiqueau commented 3 weeks ago

@rosostolato fix for Android, iOS and Electron in release 5.7.3-1