Exporting to excel and downloading of pdf files in mobile

Hi, 

I have attached an oml of the logic to export to excel and viewing of pdf files. When i generated the native app on android, I was able to go to excel and pdf applications in my phone, however, i received the warning of "Try saving the file on the device and then opening it" from my phone. I have no idea why this is happening, could anyone point out what is the issue? 

Hello Jolene,

Is this warning happening in which action, GenerateExcelOnClick or PreviewPdfOnClick?

Did you try to debug using your Android device?


Kind regards,

Rui Barradas

Rui Barradas wrote:

Hello Jolene,

Is this warning happening in which action, GenerateExcelOnClick or PreviewPdfOnClick?

Did you try to debug using your Android device?


Kind regards,

Rui Barradas

Hi Rui Barradas,

It happens for both actions, GenerateExcelOnClick and PreviewPDFOnClick.

Yes, i generated the app on an Android device. So the relevant plugins are installed properly. 


Hi Jolene,

Did you try to use the SaveFile action from FilePlugin, instead the DownloadFile?

Leandro Correa wrote:

Hi Jolene,

Did you try to use the SaveFile action from FilePlugin, instead the DownloadFile?

Hi,

May i know what is the difference between SaveFile and DownloadFile. They are from different plugins with different input parameters, however, they seem to be performing similar functions of saving a file during the uploading process. 


I think that is not the problem. I have both plugins working in different applications.

SaveFile action (FilePlugin) saves a file in the device having a binary as an input parameter. DownloadFile action (FileTransferPlugin) saves a file in the device having an URL as an input parameter. Altough the file paths work different in both actions, the FileTransferPlugin depends on the FilePlugin and they work just fine.

In my opinion, I always prefer the SaveFile action, since it is more simple and I don't need to install an extra plugin in my application, but it should be all good with the DownloadFile as well.

Did you try to debug your actions? What is the outcome?


Kind regards,

Rui Barradas

Rui Barradas wrote:

I think that is not the problem. I have both plugins working in different applications.

SaveFile action (FilePlugin) saves a file in the device having a binary as an input parameter. DownloadFile action (FileTransferPlugin) saves a file in the device having an URL as an input parameter. Altough the file paths work different in both actions, the FileTransferPlugin depends on the FilePlugin and they work just fine.

In my opinion, I always prefer the SaveFile action, since it is more simple and I don't need to install an extra plugin in my application, but it should be all good with the DownloadFile as well.

Did you try to debug your actions? What is the outcome?


Kind regards,

Rui Barradas

Hi Rui Barradas,

I tried to separate the logic. One for uploading and one for downloading. 

For the uploading one, I have an entity of Employers with attributes name, file (binary data) and file name (text). i have a form where i used the upload widget and it accepts any forms of file. In the logic, i create employer, then i check whether the plugin is available and i save file as shown below. 


Then i have a download button where users can download the file that is uploaded. the logic is as shown below:

The javascript code is as follows:
$parameters.FilePath = cordova.file.externalDataDirectory;

FilePath is a local variable in both logic with data type as text. 

The uploading logic works fine, as the success message appeared. However, the download logic does not work as when i press the button, nothing happens. I am trying the app using my Android device. 

Is there something i am missing out? 

And since you have the uploading and downloading process working, do you mind sharing a sample oml of the whole process of uploading and downloading of files in native app? 

Thank you!

Hi Jolene,

I was checking your logic.

Why are you creating an Employee before saving the file? What is the value of the variable FilePath that you use as an input parameter for the SaveFile action?

If you want to use the OpenDocument to open the file, the filePath input parameter of that action should be the Uri output parameter from the SaveFile action.

Also, in the OpenDocument action:

  • The variable isToPreview should be True;
  • The mimeType should be "application/pdf" if your file is a pdf and "application/octet-stream" otherwise.


Kind regards,

Rui Barradas

Rui Barradas wrote:

Hi Jolene,

I was checking your logic.

Why are you creating an Employee before saving the file? What is the value of the variable FilePath that you use as an input parameter for the SaveFile action?

If you want to use the OpenDocument to open the file, the filePath input parameter of that action should be the Uri output parameter from the SaveFile action.

Also, in the OpenDocument action:

  • The variable isToPreview should be True;
  • The mimeType should be "application/pdf" if your file is a pdf and "application/octet-stream" otherwise.


Kind regards,

Rui Barradas

Hi Rui Barradas,

Thank you for helping. 

I created employee first because in the form, the users are supposed to fill in particulars such as name and upload a pdf file of their resume. So i would have to create a new record for that employee in database and also have a space in database to store the pdf file as binary data. 

I believe the variable of FilePath is empty because it is just a local variable with data type text. (I am actually not sure what to do at this step)

For my application, if i were to separate the upload and download button, then how do i pass the uri from screen to screen?

Also, I actually managed to get the logic for GenerateExcelOnClick to work (i could go to the excel application on my android phone with the correct data stored in the excel, except that it was in Read-Only mode). The puzzling thing is that the logic flows the same way as my screenshots in my previous reply. My input parameter FilePath for the SaveFile action seems to be empty. Also i did not pass the output parameter of URI from the SaveFile action to the OpenDocument action. 

I attached an oml so that you can view my logic better. 

Thank you!


Hi Jolene,


"I believe the variable of FilePath is empty because it is just a local variable with data type text. (I am actually not sure what to do at this step)"

  • If you are not passing any value in the variable FilePath, probably you are not saving any file into the device, but the action is not giving any error and that's why you see the success feedback message.

For my application, if i were to separate the upload and download button, then how do i pass the uri from screen to screen?

  • What I said it's different. I said about the OpenDocument action, not the upload action. This action should receive the Uri output parameter from the SaveFile action. Most likely, they will be in the same flow, since you will open the file after the download/save.


Let me know if you have any further questions. If you do, I can show you my logic regarding to those plugins.


Kind regards,

Rui Barradas

Rui Barradas wrote:

Hi Jolene,


"I believe the variable of FilePath is empty because it is just a local variable with data type text. (I am actually not sure what to do at this step)"

  • If you are not passing any value in the variable FilePath, probably you are not saving any file into the device, but the action is not giving any error and that's why you see the success feedback message.

For my application, if i were to separate the upload and download button, then how do i pass the uri from screen to screen?

  • What I said it's different. I said about the OpenDocument action, not the upload action. This action should receive the Uri output parameter from the SaveFile action. Most likely, they will be in the same flow, since you will open the file after the download/save.


Let me know if you have any further questions. If you do, I can show you my logic regarding to those plugins.


Kind regards,

Rui Barradas

Hi Rui Barradas,

For your first bullet point, I think it is being saved into the device for the GenerateExcelOnClick because i was able to open the excel file. If it was not being saved into the device, I will not be able to open the excel file (which was what happened at first in my attached oml in my first post). 

For your second bullet point, i will not need to open the file after download/save. It is like one user will upload a pdf of their resume on their application. That user will not need to open the pdf of their resume. He or she will just be uploading. But for other user (employers for eg) will have to open the document and view the resume, without uploading. That is why i will have to separate the uploading and downloading logic flows. 

I tried my oml in my Android device but it doesn't work, (the screen just stays the same after i press the download button). However, i believe it is the JavaScript code of $parameters.FilePath = cordova.file.externalDataDirectory; that result in my device going to another application in my phone (as seen from GenerateExcelOnClick). However, in my download logic, I also have the same JavaScript code but it doesnt result in me going to another application. This part is confusing me, because i believe both the process of generating an excel sheet should be similar or exactly the same as the process of uploading and downloading right? But the logic flows works for excel but not for pdf....

I would be glad if you could explain the differences if there are any? It would be able great to see a sample oml of how these plugins actually works. I have been doing mostly trial and error without knowing the reasons why some steps are taken. 

Edit: I also have an additional question. In my situation i mentioned above (employees uploading resumes and employers downloading them), how do i ensure that when employers click on a specific employee's resume, the correct resume gets downloaded? How is the correct resume determined? Also, because i want the logic flow to be applicable in various situations, does that mean the "Id" of the correct resume should be stored in a local variable...?

Thank you. 

Hi Jolene,

I propose that we do a Skype call, it will be easier for us to discuss everything you want. I will also share my screen so you can see what i'm doing in my application regarding to those plugins.

I'll send you a private message so we can arrange that.


Kind regards,

Rui Barradas

Solution

Jolene Kwek wrote:

Hi, 

I have attached an oml of the logic to export to excel and viewing of pdf files. When i generated the native app on android, I was able to go to excel and pdf applications in my phone, however, i received the warning of "Try saving the file on the device and then opening it" from my phone. I have no idea why this is happening, could anyone point out what is the issue? 

Hi Jolene,
I have made available a sample on forge that covers the scenarios you are looking for, I believe. 

Take a look: https://www.outsystems.com/forge/component-overview/8322/fileviewerdemo


I hope it helps.

Otávio. 



Solution