capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

bug: File downloads not working

Open Feuerhamster opened this issue 10 months ago • 2 comments

Bug Report

Capacitor Version

Capacitor Doctor

Latest Dependencies:       

  @capacitor/cli: 5.3.0    
  @capacitor/core: 5.3.0   
  @capacitor/android: 5.3.0
  @capacitor/ios: 5.3.0    

Installed Dependencies:    

  @capacitor/ios: not installed    
  @capacitor/cli: 5.3.0
  @capacitor/core: 5.3.0
  @capacitor/android: 5.3.0        

[success] Android looking great! 👌

Platform(s)

  • Android

Current Behavior

If you click on the button that should initialize the download, nothing happens. The android debugger does not show any errors.

Expected Behavior

The user should be prompted to save the file to the downloads folder. Exactly how you would download a file from a website in a browser.

Code Reproduction

import { db } from "$lib/database";
import FileSaver from "file-saver";

async function download() {
  const data = JSON.stringify(await db.table.toArray());
  var blob = new Blob([data], {type: "application/json;charset=utf-8"});
  FileSaver.saveAs(blob, `app-user-data-${Date.now()}.json`);
}

Other Technical Details

npm --version output: 9.6.7

node --version output: v18.17.1

pod --version output (iOS issues only):

Additional Context

What I basically want to achieve is that the user can export the data of the app to a json file so the user can back up data or use it for data analysis. I checked, it is not a problem of the libary FileSaver I am using. The native js way with creating an a element to download a text file is also not working.

Feuerhamster avatar Sep 09 '23 23:09 Feuerhamster