Cordova Read/Write binary file

4 posts, 0 answers
  1. Jay O'Brien
    Jay O'Brien avatar
    39 posts
    Member since:
    Dec 2008

    Posted 18 Oct Link to this post

    I found the requestFileSystem to read and write to a text file which works fine for text ... is there an API to read and write a binary file?

    In my app, I want to download a file from a server, and write it to storage inside my app.

    Thanks!

  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 21 Oct Link to this post

    Hi,

    This functionality can be incorporated in your app using the File Transfer plugin which you can see in action here. It allows for downloading a file from a remote resource and storing it on the device file system.

    Let me know if this works for you.

    Regards,
    Anton Dobrev
    Telerik by Progress
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
  3. Jay
    Jay avatar
    87 posts
    Member since:
    Nov 2007

    Posted 21 Oct in reply to Anton Dobrev Link to this post

    That works great, thx.

    For a related question, how can I launch that downloaded file (e.g. DOCX, PPTX, PDF, etc) using the associated application on the device? PDFs and images can probably simply be opened with window.open .... but what about other file types? Is there a way to launch them and just have whatever app is associated with the file type take over?

    Thanks!

  4. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 26 Oct Link to this post

    When the file is located on the device you can open it in several ways, using the local URI:

    - in a object or anchor element with the respective URI as a source (for both platforms this should trigger the suggestion for an app that supports the flie type)
    - using the InAppBrowser
    - using a custom plugin (this is Android only - https://www.npmjs.com/package/cordova-plugin-fileopener and I am not aware of such for iOS)

    Let me know if this works for you.

    Regards,
    Anton Dobrev
    Telerik by Progress
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top