question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cant download file properly to a user accessible location

See original GitHub issue

I am using the HTTP library to attempt to download a file.

In short, I want to download a file, from a URL, to my device in a place where the user can access it easily.

For simplicity in getting it working the first time I am using the example from the docs.

This is the code I am using:

download (id) {
        console.log('Download Started');
        getFile("https://raw.githubusercontent.com/NativeScript/NativeScript/master/apps/tests/logo.png").then(function (r) {
            console.log(r.path);
        }, function (e) {
            //// Argument (e) is Error!
        });
    }

This outputs the path it was saved at as being:

/data/user/0/com.myapp.example/files/logo.png

When I try to go to this location on a file browser from the play store It is nowhere to be found.

Can anyone shed anymore light on this?

Obviously, I want this to work the same on ios and Android but I am testing on Android atm.

Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
kumarandenacommented, Dec 29, 2017

@NickIliev How to use http getFile function with nativescript angular? I have looked in NS Angular http class, but its not having the getFile funtion.

2reactions
NickIlievcommented, Dec 21, 2016

@RyanSMurphy, in order to access the native APIS, thought any TypeScript enabled project you will need the TypeScript declaration files for the native APIs. The good news is that you don’t need to generate those files as we are providing them with tns-platform-declarations package. However to enable them under Angular-2 project requires some additional steps as follows:

npm i tns-platform-declarations --saveDev

then open tsconfig.json and add the lib option

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "experimentalDecorators": true,
        "lib": [
            "es2016"
        ]
    }
}

and finally open references.d.ts and modify its tcontent to look like this

/// <reference path="./node_modules/tns-core-modules/tns-core-modules.es2016.d.ts" />

/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />

declare type Comment = any;
declare type CloseEvent = any;
declare type Document = any;
declare type DocumentFragment = any;
declare type Element = any;
declare type History = any;
declare type HTMLAnchorElement = any;
declare type HTMLCollection = any;
declare type HTMLDocument = any;
declare type HTMLElement = any;
declare type HTMLInputElement = any;
declare type HTMLScriptElement = any;
declare type HTMLStyleElement = any;
declare type KeyboardEvent = any;
declare type Location = any;
declare type MessageEvent = any;
declare type MouseEvent = any;
declare type Node = any;
declare type NodeList = any;
declare type Text = any;
declare type WebSocket = any;

For reference, you can take a look at how these are set in this application.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix file download errors - Google Chrome Help
If you try to download a file and it doesn't work, first try to fix the error with these troubleshooting steps: Make sure...
Read more >
How to Deny or Allow Access to Downloads Folder ... - YouTube
Windows 10 Privacy Settings offer File System settings, which makes sure that ... If a user allows apps access to their Downloads folder, ......
Read more >
[Solved] Can't Open Downloads Folder in Windows 10
The first thing to do when you see a not responding/inaccessible Downloads folder is to run the System File Checker. The purpose of...
Read more >
Microsoft Edge Can't Download Files? Here's How to Fix It
Open the browser's menu. Head to Settings > Downloads. Click Change next to Location and set a new download path. Check if Edge...
Read more >
What to do if you can't download or save files | Firefox Help
1 Check the Downloads panel for blocked downloads · 2 Clear the download history · 3 Choose a different download folder · 4...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found