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

Trusted Contributor
Posts: 118
Registered: ‎03-06-2013
My Device: Blackberry Z10
My Carrier: Airtel

FileTransfer Download API , downloads file at wrong path

hello all,

I am using following function to download a file:


function downloadFiles(fileName, sourceFilepath, targetFilepath, successCallback, failureCallback) {
         window.requestFileSystem(LocalFileSystem.TEMPORARY, 1024*1024, gotFS, fail);
        function gotFS(fileSystem) {
            fs = fileSystem.root;
            fileSystem.root.getDirectory("new_assets", { create: true, exclusive: false }, gotDirectoryEntry, fail);

        function gotDirectoryEntry(dirEntry) {
            fs.getFile("new_assets/"+fileName, { create: true, exclusive: false }, gotFileEntry, fail);

        function gotFileEntry(fileEntry) {
            var ft = new FileTransfer();    // create ft object
            var localPath = fileEntry.fullPath;

            ft.download(sourceFilepath+fileName, fileEntry.fullPath, function(entry) {  // initiate download 
            }, onError1);

            function onError1(e){
            	alert("FILE DOWNLOAD ERROR: " + e.code + ':' + e.http_status);
        function fail(error) {    // function called incase of fail 
        	console.log("ERROR: " + error.code + ':' + error.http_status);

 this is what i am trying to do with above API,

1. getting temporary filesystem.

2. creating a directory entry called new_assets under temporary filesystem

3. creating an entry called config.json under that new_assets directory created.

4.creating a filetransfer object to intiate download of the file config.json from a server location.


i am successfully able to download the file from server, but the file creates outside new_assets folder and the name of the file is new_assetsconfig.json.


i am really confused why this issue is happening. the same logic is used in Andriod and IOS and the download at correct location is happening without any problem. 


Please help me out in resolving the issue.

- If a post contains the solution to the problem, please click "Accept as Solution"
- If a post contains helpful content, please give it a "Thumbs Up"

Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: FileTransfer Download API , downloads file at wrong path



I have to build a quick sample because looking through FileSystem source makes me cross-eyed Smiley Tongue  I feel like things are a little more complicated than need be (like why do we create the file entry and then create it again with ft.download?).  It shouldn't take me more than 15 minutes so I'll get back to you soon!




-_- zZZ
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: FileTransfer Download API , downloads file at wrong path

Are you indeed able to download the file from the server?  I get a permissions denied error as the target specified when we call blackberry.io.filetransfer would be the real filesystem and not the sandboxed filesystem within the app.  Your best bet would be to save this file to the real filesystem using blakberry.io.sandbox = false or downloading the file to the real filesystem first (specify '/accounts/1000/shared/downloads' as the target folder) and then saving to your sadboxed filesystem.  Does that make sense??  I hope so!

-_- zZZ
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: FileTransfer Download API , downloads file at wrong path

Just based on the source provided, I would expect this section to be where the issue occurs:


ft.download(sourceFilepath+fileName, fileEntry.fullPath, function(entry) {

Have you confirmed that sourceFilePath does actually include a / symbol at the end?

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.