Nativescript-angular: How can I download a file and save to the device?

Created on 26 Jan 2018  路  4Comments  路  Source: NativeScript/nativescript-angular

Im using POST Method and response is PDF 1.4, how i can save it?
this.http.post(url, JSON.stringify(data), { headers: this.headers })
.toPromise()
.then((response) => response)
.catch(this.handleError);

All 4 comments

Hi @Nurgunkalol,
Thank you for contacting us
To save the file which you received from the request, you could try using the writeSync method provided by File-System module, which will allow you to save the binary data, which you get from your backend service.

this.testFile.writeSync(this.binarySource, err => {
    console.log(err);
});

For further info, you could also review this article in our documentation, where the usage of this method has been demonstrated.

Hope this helps

@tsonevn the link is broken

HI @alereisan,
I have updated the link with the correct one.

And how can I save the file in external storage ?
Create folder after save the file in my folder created
the path is "/storage/emulated/0/myFolder/myFile.pdf" for example

Was this page helpful?
0 / 5 - 0 ratings