Skip to content

Instantly share code, notes, and snippets.

@NickIliev
Last active November 22, 2018 13:43
Show Gist options
  • Save NickIliev/acbe113f0fa7b438464a188062c7bfa6 to your computer and use it in GitHub Desktop.
Save NickIliev/acbe113f0fa7b438464a188062c7bfa6 to your computer and use it in GitHub Desktop.
Firebase Storage Download a File (NativeScript)
downloadFile() {
let downloadPath: string;
let logoPath: string;
let fileName: string = "happy-homer-meme.png";
if (isAndroid) {
// use tns-platform-declarations to access the native Android & iOS APIs
downloadPath = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS).toString();
} else if (isIOS) {
downloadPath = knownFolders.documents().path;
}
logoPath = path.join(downloadPath, fileName);
// Download the file with the options below:
storage.downloadFile({
// optional, can also be passed during init() as 'storageBucket' param so we can cache it
bucket: APPSPOT_BUCKET_URL,
// the full path of an existing file in your Firebase storage
remoteFullPath: 'uploads/images/happy-homer-meme.png',
// option 1: a file-system module File object
localFile: File.fromPath(logoPath),
// option 2: a full file path (ignored if 'localFile' is set)
localFullPath: logoPath
}).then(uploadedFile => {
console.log("File downloaded to the requested location");
console.log("uploadedFile: ", uploadedFile);
}).catch(err => {
console.log("File download error: " + err);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment