[File Transfer Plugin] Multiple Download File Widgets

[File Transfer Plugin] Multiple Download File Widgets

  
Forge Component
(4)
Published on 5 Mar by Experts
4 votes
Published on 5 Mar by Experts

Hi,

not sure if I'm missing something or other forces are at play... Here is my predicament:

Let's say, there is a Screen1 with the DownloadFile widget on it. All three event handlers have been assigned. There is a screen action which calls DownloadFile action (with correct parameters) and everything works as expected :) the events get triggered as expected and the event handlers are called... All good.

But, I also have a Screen2 with a DownloadFile widget on it. All three event handlers have been assigned. The Screen2 has its own action which calls DownloadFile action (with correct parameters) and the file is indeed downloaded. However, it appears no events are raised or at least, none of the specified event handlers are called...

so, what we have here is a one mobile application (Android), two screens, each screen with its own DownloadFile widget. All event handlers defined on the first screen are being called. No event handler on the second screen is being called. The file is correctly downloaded from both screens...

any clues?

many thanks

Hi D1,

could you upload a module/application containing your example? It would make it easier to pinpoint the problem you are facing.


greetings,

pedro

Hi again,

I tried to replicate your scenario, but I couldn't. I have two screens in place, each with a FileDownload widget in place and each with its own event handlers. When I'm downloading a file from the first one I see the event handlers associated with the first screen being called. When I'm downloading a file from the second one I see the event handlers associated with the second screen being called.


Details of my setup:

platform server: 10.0.702

File Transfer Plugin: 2.0.1

File Plugin: 1.0.3

CommonPlugin: 2.3.0

File Transfer Sample: 1.0.0


What did I do?

1. Added a "fake" dependency from the File Transfer Plugin to the File Plugin. This dependency is necessary, otherwise we get an error stating that the plugin could not be compiled (see: https://www.outsystems.com/forums/discussion/31998/filetransfer-error-compiling-cordova-plugin/).

2. Changed the File Transfer Sample by creating a copy of the home screen. This screen contains a Download Widget and the corresponding event handlers. 

3. A link to the copy of the home screen was added to the menu, to be able to switch easily between the two.

4. Generated an android mobile app for debug purposes (Build Type: Debug)

5. Installed the app in the smartphone (Android version 7.0).

6. Enabled the developer tools in the smartphone and set USB debugging to true

7. Connected the smartphone through USB to the laptop 

8. Started the debugger in Service Studio on the device and added breakpoints at the start of each event handler, of both the home screen and the copy of the home screen.

9. Opened the home screen in the mobile app, entered a valid URL to download from (e.g. http://www.nos.nl) and pressed Download. The debugger stopped first on the breakpoint of the DownloadFileOnDownloadProgress event handler and later on the breakpoint of the DownloadFileOnDownloadComplete event handler, both of them associated with the home screen.

10. Switched in the mobile app to the copy of the home screen and performed the same actions. The debugger stopped on the breakpoints of the event handlers associated with the copy of the home screen.


Please find attached the File Transfer Sample oap with the changes I died.


Hope this helps.


greetings,

pedro

Hi Pedro,

thanks for your prompt reply :)

...after "deeper" analysis, I've identified my problem. It was an event that I've fired straight after the call to DownloadFile client action which caused another block to become active... I've fixed the issue, however the solution is somewhat inelegant. I was wondering if it would be possible to implement another Output Parameter (alongside the Error structure) that would contain the size of the requested file (and potentially some other useful info). In my particular case, such information would enable me to asynchronously check if the file has been transferred in its entirety and not have to "hold" caller block active until OnDownloadComplete event is triggered.

thanks for your assistance

Dean

Hi Dean,

my pleasure. I don't understand what you are trying to achieve. I find it strange when you say that you want to check if the file has ben transferred in its entirety in an asynchronous manner. I interpret this as if you were saying that you would like to check whether the download has completed, every once in a while. If this is the case, why don't you just make use of the OnDownloadComplete event? Then you don't need to check it yourself, every once in a while, as you'll be notified as soon as the download has terminated. This is more efficient and is also easier to program.

I'd like to help you in here but I do think that in order to do that it helps if you upload a small oap with your solution.


greetings,

pedro 

Hi Pedro,

just try to send your code to another Destination straight after calling DownloadFile action. Providing, download is not completed in that split second, OnDownloadComplete event handler will not be called, even though the file will be downloaded. And that is why I would like to be able to check whether the download has been completed without having to rely on the event...

cheers

Dean

Solution

Hi Dean,

I see your problem. If you are leaving the screen immediately after calling the DownloadFile action, the controller of that screen gets disposed (is not active anymore). As the event handlers are associated with the controller, they are still called but the platform does not execute them, due to the controller not being active, and throws a ControllerDisposedException instead. 

What can you do? 

a) You could avoid leaving the page and just integrate the page that you want to navigate to in the page you are at. After starting the download you could hide the download part of the page and show the other part of the page.

b) Alternatively, you can still navigate to a new page. In order to get the size of the file, you could do an http head request to the url of the file to download, just ahead of the DownloadFile action. In the Content-Length header of the response you find the size of the file you are about to download. You can use for example the ardoHTTP forge component in order to perform an http head request and retrieve the Content-Length. Just check whether the Content-Length is actually returned upon an http head request from the servers that host the files. I've noticed that in some cases it is not being returned.

Hope this helps.


greetings and good luck,

pedro


Solution

Hi Pedro,

Option b) suits my scenario perfectly

many thanks :)

Dean

Hi Dean,

you're welcome.

greetings,

pedro