Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
denniskis
Posts: 33
Registered: ‎10-29-2013
My Device: BB10
My Carrier: TMO
Accepted Solution

How to invoke Browser/save as/download window?

Hi,

I would like the user to click a link with href to external file which would open a browser save as window. Is it possible with webworks for bb10?

I tried to use download for <a> tag but it's not working.

 

Thanks

Please use plain text.
Developer
miamon
Posts: 181
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone

Re: How to invoke Browser/save as/download window?

[ Edited ]
Please use plain text.
BlackBerry Development Advisor
chadtatro
Posts: 614
Registered: ‎10-01-2009
My Device: Z10
My Carrier: Bell

Re: How to invoke Browser/save as/download window?

That's right, 

 

If you just add an href it'll redirect your application to that url when the user clicks it.

 

I'd recommend using a Child Browser, it'll open a new view (with a close button). That way the user never actually has to leave your application.

 

If the use-case is to download a file from said link then I would use what Miamon mentioned, the fileTransfer API.

Chad Tetreault | App Development Consultant | BlackBerry Developer Relations | developer.blackberry.com | @chadtatro
Please use plain text.
Developer
denniskis
Posts: 33
Registered: ‎10-29-2013
My Device: BB10
My Carrier: TMO

Re: How to invoke Browser/save as/download window?

thanks for replies. I was just wondering why it is not working smth like this <a href="link path" download="filename"> </a>

I try to load an external audio file and the browser starts to play it instead of loading by default. The build in file transfer API doesn't show progress when loading a file. So it is very user unfriendly.

Please use plain text.
BlackBerry Development Advisor
chadtatro
Posts: 614
Registered: ‎10-01-2009
My Device: Z10
My Carrier: Bell

Re: How to invoke Browser/save as/download window?

It's doesn't work because as you've discovered, the browser will play the file by design. :smileyhappy:

 

If the FileTransfer API isn't what you're hoping it was right now then I'd suggest you take a look at XHR. You can get progress events. It sounds like that's what you're going for. Note that it'll be more work than the FileTransfer API as you'll have to manually save the downloaded file blob to the filesystem yourself.

 

Here's a link to the best XHR2 article ever written, it covers a lot of different use cases: http://www.html5rocks.com/en/tutorials/file/xhr2/

 

 

Chad Tetreault | App Development Consultant | BlackBerry Developer Relations | developer.blackberry.com | @chadtatro
Please use plain text.