1141
Views
10
Comments
Solved
[File Viewer Plugin] [Mobile offline] Open PDF from entity's binary data
file-viewer-plugin
Mobile icon
Forge asset by OutSystems

How to open pdf (which is binary data in an entity) in offline mode ? Target is for both iOS and Android devices. I am able to display nicely when mobile is online. For offline mode, I tried below 




2017-10-11 09-17-52
Valerie
Solution

Hi using the File Plugin we used Create Directory to create a folder for the app in the phone then we used the SaveFile to save the binary file in the folder created. This path cannot be accessed unless the phone is jail break or rooted. so Example the path is "com/test/MobileApp"

Then for the GetFileURI that is the path that we put. 


Note that for the SaveFile no need to convert to base64 you can directly point the binary data from Local Storage.

Mukul Varshney wrote:

Valerie wrote:

Hi,

Try using the File Plugin from Forge  to save the binary file locally. 

Use the File Plugin to save it locally. 

use the GetFileURI to get the path then place it in filePath in OpenDocument to open the binary file.




Path property of the client action GetFileURI will be 

"data:application/pdf;base64," + JavaScript1.Base64

Is it correct ?



UserImage.jpg
Pedro Sousa

Unfortunately, this Forge component doesn't support opening/previewing files straight from their base64-encoded contents.

You can try to wrap the cordova-plugin-file-opener2 cordova plugin, which supports your use case through the openBase64() method, in an OutSystems plugin.

Check "Create a Plugin to Use Mobile Capabilities in Your Application" for more information on how to do this.

UserImage.jpg
Mukul Varshney

Pedro Sousa wrote:

Unfortunately, this Forge component doesn't support opening/previewing files straight from their base64-encoded contents.

You can try to wrap the cordova-plugin-file-opener2 cordova plugin, which supports your use case through the openBase64() method, in an OutSystems plugin.

Check "Create a Plugin to Use Mobile Capabilities in Your Application" for more information on how to do this.

Thanks Pedro.

Tried creating the plugin using CommonPlugin, but it fails as FileOpener undefined.Replacing FileOpener with FileOpener2 has same result.

if(typeof(cordova.plugins.FileOpener) === "undefined")
    $parameters.PluginExists = false;
else
    $parameters.PluginExists = true;




UserImage.jpg
Mukul Varshney

Mukul Varshney wrote:

Pedro Sousa wrote:

Unfortunately, this Forge component doesn't support opening/previewing files straight from their base64-encoded contents.

You can try to wrap the cordova-plugin-file-opener2 cordova plugin, which supports your use case through the openBase64() method, in an OutSystems plugin.

Check "Create a Plugin to Use Mobile Capabilities in Your Application" for more information on how to do this.

Thanks Pedro.

Tried creating the plugin using CommonPlugin, but it fails as FileOpener undefined.Replacing FileOpener with FileOpener2 has same result.

if(typeof(cordova.plugins.FileOpener) === "undefined")
    $parameters.PluginExists = false;
else
    $parameters.PluginExists = true;




Able to locate the problem and proceed,

if(typeof(cordova.plugins.fileOpener2) === "undefined")
    $parameters.PluginExists = false;
else
    $parameters.PluginExists = true;


Still it does not open the PDF file.

2017-10-11 09-17-52
Valerie

Hi,

Try using the File Plugin from Forge  to save the binary file locally. 

Use the File Plugin to save it locally. 

use the GetFileURI to get the path then place it in filePath in OpenDocument to open the binary file.




UserImage.jpg
Mukul Varshney

Valerie wrote:

Hi,

Try using the File Plugin from Forge  to save the binary file locally. 

Use the File Plugin to save it locally. 

use the GetFileURI to get the path then place it in filePath in OpenDocument to open the binary file.




Path property of the client action GetFileURI will be 

"data:application/pdf;base64," + JavaScript1.Base64

Is it correct ?

2017-10-11 09-17-52
Valerie
Solution

Hi using the File Plugin we used Create Directory to create a folder for the app in the phone then we used the SaveFile to save the binary file in the folder created. This path cannot be accessed unless the phone is jail break or rooted. so Example the path is "com/test/MobileApp"

Then for the GetFileURI that is the path that we put. 


Note that for the SaveFile no need to convert to base64 you can directly point the binary data from Local Storage.

Mukul Varshney wrote:

Valerie wrote:

Hi,

Try using the File Plugin from Forge  to save the binary file locally. 

Use the File Plugin to save it locally. 

use the GetFileURI to get the path then place it in filePath in OpenDocument to open the binary file.




Path property of the client action GetFileURI will be 

"data:application/pdf;base64," + JavaScript1.Base64

Is it correct ?



2021-07-21 10-26-16
Vani Mankad

Mukul Varshney & Valerie : With above solution , i was able to achieve the functionality of downloading PDF from mobile app through binary data. Thank you for the same.

However, i wanted to know that after using this plugin, when we deploy the version to production, End user would be required to reinstall the app or just update it from play store ? It would not be good to get the app reinstalled by thousands of users just for one change in app.

Please let me know if anyone has faced such issue. Thanks.

UserImage.jpg
Mukul Varshney

Vani Mankad wrote:

Mukul Varshney & Valerie : With above solution , i was able to achieve the functionality of downloading PDF from mobile app through binary data. Thank you for the same.

However, i wanted to know that after using this plugin, when we deploy the version to production, End user would be required to reinstall the app or just update it from play store ? It would not be good to get the app reinstalled by thousands of users just for one change in app.

Please let me know if anyone has faced such issue. Thanks.


After adding any new plugin we need to generate and have a new build for the app. This new build has to be published to the app store. Probably, a new installation required on phones.

2021-07-21 10-26-16
Vani Mankad

Is that the case for Production deployment as well ? I understand for Development environment, it will require to get reinstalled the app because the build will be deployed on "Debug" mode.

But for Production deployment also we need user to get it reinstalled the app ?

UserImage.jpg
Mukul Varshney

I cannot confirm, most likely the app has to be reinstalled by the user as the cordova plugin is changed and the hence the app has be installed again.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.