Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filesystem.downloadFile fails for unknown reason #2239

Open
bengrah-miller opened this issue Nov 7, 2024 · 2 comments
Open

Filesystem.downloadFile fails for unknown reason #2239

bengrah-miller opened this issue Nov 7, 2024 · 2 comments

Comments

@bengrah-miller
Copy link

bengrah-miller commented Nov 7, 2024

Bug Report

Plugin(s)

"@capacitor/filesystem": "^6.0.1",

Capacitor Version

npx cap doctor
   Capacitor Doctor   

Latest Dependencies:       

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

Installed Dependencies:    

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

[success] Android looking great! 👌

Platform(s)

Android

Current Behavior

I've got the following code in place to download a file:

    Filesystem.downloadFile({
      method: 'POST',
      data: payload,
      url: this.dataService.downloadFileAttachment(),
      headers: headers,
      directory: Directory.Documents,
      path: "test.bin",
      progress: true
    })
      .then((result) => {
        console.info("result:", result)
      })
      .catch((e) => {
        console.error("error:", e)
      })

The code runs, doesn't appear to download anything and fails pretty much instantly, I get the following error on the console:

VM3:339 result Filesystem.downloadFile (#70225240)
8054.da0d23dc07e24a1c.js:1  error: ke: Error downloading file: http://endpoint.com/download
    at returnResult (<anonymous>:943:32)
    at win.androidBridge.onmessage (<anonymous>:918:21)

Expected Behavior

File should be downloaded

Code Reproduction

See above

Other Technical Details

Additional Context

@me-cedric
Copy link

I'm encountering a similar issue and I believe that the data is not sent as a post payload.
I have to use the patched window.fetch method to perform the post, convert the result to base64 and save manually since I'm using CapacitorHttp.
But the resulting pdf file is just blank pages.

@bengrah-miller
Copy link
Author

@me-cedric Just a quick one, not sure if this applies to you or not - our endpoint is meant to send back a binary (octet-stream), but we ended up switching to CapacitorHttp.post() - when we did this, the response is coming back in base64 encoding - using atob() turns it back into the binary that we can see in Postman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants