How to download .pdf, .docx, .xlsx, ... from Binary in DB to mobile app?

How to download .pdf, .docx, .xlsx, ... from Binary in DB to mobile app?

  

Hello everybody,

I have a Application containing a Mobile App and a Backoffice Web App. In the WebApp I can easily upload several file types as binary to my database and download it using the build in download function.

Now I also want to download the files I upload to the Database to my Mobile App. On the Mobile App I want to open the files in the standard file application the user wants to use (for example .pdf opens with Safari on iOS). I'm using the File Transfer Plugin (https://www.outsystems.com/forge/component/1409/file-transfer-plugin/) and then open the file with the File Viewer Plugin (https://www.outsystems.com/forge/component/1606/file-viewer-plugin/?(Not.Licensed.For.Production)=). I managed it to download files when I have a static URL but now I also want to files coming from the Database.

Do you have any Idea how to reach that?

Thanks for your help!

Kind regards

Oliver

I just did this yesterday

Simply create a blank screen in your web app that accepts the required input parameters to identify the record. Then in the preparation select the data based on the parameters and use the download widget instead of the end node.

 additional work may be required depending on multitenant status login credentials and screen security. but that's the basic method i used.

Steve Tilden wrote:

I just did this yesterday

Simply create a blank screen in your web app that accepts the required input parameters to identify the record. Then in the preparation select the data based on the parameters and use the download widget instead of the end node.

 additional work may be required depending on multitenant status login credentials and screen security. but that's the basic method i used.

What Oliver mean is for the mobile approach. We both want to know how to implement Downloading binary files from database and move it to external folder like Document, Music, Picture.


@Oliver, did you found some solution about your concern?


Hi Oliver et al,

If I understand correctly what you're trying to do, you may extend the approach you're currently using (File Transfer Plugin and File Viewer Plugin with a static URL) with Steve's approach:

  1. create a new Web Application, and module.
    1. Add any required dependencies so it has access to the relevant Database Entities.
    2. Create a new empty Screen (name it GetFile, for instance), with any input parameters necessary to determine what to download.
    3. Add a Preparation to the new GetFile screen, that fetches the requested data from the Database, performs any needed logic and ends in a Download tool.
  2. In your Mobile application, instead of using a static URL, build a URL to the GetFile screen on the new Web Application (including any relevant input parameters). 

Would this work for your requirements? 

Hi Jorge


That makes it clear. I'll try to implement it and give you a feedback.


Regards,

Ron

Jorge Martins wrote:

Hi Oliver et al,

If I understand correctly what you're trying to do, you may extend the approach you're currently using (File Transfer Plugin and File Viewer Plugin with a static URL) with Steve's approach:

  1. create a new Web Application, and module.
    1. Add any required dependencies so it has access to the relevant Database Entities.
    2. Create a new empty Screen (name it GetFile, for instance), with any input parameters necessary to determine what to download.
    3. Add a Preparation to the new GetFile screen, that fetches the requested data from the Database, performs any needed logic and ends in a Download tool.
  2. In your Mobile application, instead of using a static URL, build a URL to the GetFile screen on the new Web Application (including any relevant input parameters). 

Would this work for your requirements? 

I did exactly what you said but it works on the emulator but not on the real phone. Do you know what I am missing?

Thanks


Hi Filipa,

How are you testing it on the device? You will have to generate a native app as the OutSystems Now app does not include the required plugins...

Jorge Martins wrote:

Hi Filipa,

How are you testing it on the device? You will have to generate a native app as the OutSystems Now app does not include the required plugins...


I generated an android application in Debug mode

Did you generate the App before or after you referenced the new plugins? and did you update the APK installed on your device after that or just relied on the automatic update of application code?

I ask all these questions because every time you reference a new plugin in your application you will need to regenerate the native application and install the new version explicitly on the device (download APK, install, etc), otherwise the plugin binaries will not be available and your application will not behave as expected.

Hello Jorge,

first I want to say thanks for your help :)

But I have the same problem as Filipa. The function works fine in the Outsystem Now App and in the emulator. But on the native App side there are two different problems:

Android: Nothing happend here. The download don´t start. Also try the puplish the app and install it on the phone again, didn´t help.

IOS: Here the function itselfe works. But the data weren´t downloaded, they are just showen. I can´t download it or scroll / zoom into the image.


I test it with pictures and pdfs. The Mime typ is also given to the dowload function.

Do you now a solution for this problem?


Thanks and Best Regards
Thomas

Hello everyone


Have you tried using File Plugin or File Transfer Plugin for the download and File Preview for viewing files?



Regards,

Ron

Hello Ron,


I also tried File Transfer Plugin with a similiary problem as result (data doesn´t download correctly).
File Preview is not needed, because I have differnt data types (excel, word, pdf, jpeg, txt, etc.), so a view is not necessary.

Only the File Pluign I didn´t try. The goal should be to download and open the data with the typical feel and look of the operating system (android, ios).

I managed to make it work by using the InAppBrowser plugin so when you click on the attachment, you are redirected to a web page and the download starts. 

The only problem is that you have to close this web page by yourself. 

I know that you can you use this plugin so it opens in the app itself but this way the download doesn't start.

Hi Filipa


Hmm Interesting, with your approach the file will be located at the download folder. When using the plugin above the downloaded files are stored inside the application folder/sub folder. 


Regards,

Ron

Hello,


The approach of a blank screen does not work with File Transfer Plugin.

I receive an error saying:

E/FileTransfer(2633): {"code":1,"source”:”MyURL…,”target":"","http_status":200,"exception":"\/ (Is a directory)"}

E/FileTransfer(2633): java.io.FileNotFoundException: / (Is a directory)

E/FileTransfer(2633): at java.io.FileOutputStream.open(Native Method)

E/FileTransfer(2633): at java.io.FileOutputStream.<init>(FileOutputStream.java:221)

E/FileTransfer(2633): at org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:329)

E/FileTransfer(2633): at org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:310)

E/FileTransfer(2633): at org.apache.cordova.filetransfer.FileTransfer$4.run(FileTransfer.java:898)

E/FileTransfer(2633): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)

E/FileTransfer(2633): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)

E/FileTransfer(2633): at java.lang.Thread.run(Thread.java:761)


I believe the problem is what I pass in FileSystemURL.

What path I have to pass?

in this component's git hub: https://github.com/apache/cordova-plugin-file-transfer#binaryFile

It says that you have to crete a path before.


Any help? 

My bad... just checked the sample and found it on OnReady Function!

Cheers