Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit bc04d9f

Browse files
committed
Merge branch 'master' of https://github.com/EddyVerbruggen/nativescript-plugin-firebase into shared-delegate
2 parents 1ced357 + 37fda4d commit bc04d9f

File tree

12 files changed

+131
-17
lines changed

12 files changed

+131
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
- [Firebase iOS SDK Changelog](https://firebase.google.com/support/release-notes/ios)
44
- [Firebase Android SDK Changelog](https://firebase.google.com/support/release-notes/android)
55

6+
## 10.3.3 (2019, Dec 24)
7+
[Fixes & Enhancements](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/milestone/121?closed=1)
8+
9+
610
## 10.3.2 (2019, Dec 11)
711
[Fixes & Enhancements](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/milestone/120?closed=1)
812

demo-ng/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"nativescript-angular": "~8.0.3",
2626
"nativescript-camera": "~4.5.0",
2727
"nativescript-imagepicker": "~6.2.0",
28-
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-10.3.2.tgz",
28+
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-10.3.3.tgz",
2929
"nativescript-theme-core": "~1.0.6",
3030
"reflect-metadata": "~0.1.13",
3131
"rxjs": "~6.5.2",

demo-push/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
},
1111
"dependencies": {
12-
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-10.3.2.tgz",
12+
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-10.3.3.tgz",
1313
"nativescript-theme-core": "~1.0.6",
1414
"nativescript-unit-test-runner": "0.7.0",
1515
"tns-core-modules": "~6.1.1"

demo-vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
},
1616
"dependencies": {
17-
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-10.3.2.tgz",
17+
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-10.3.3.tgz",
1818
"nativescript-theme-core": "~1.0.6",
1919
"nativescript-vue": "~2.4.0",
2020
"tns-core-modules": "~6.1.1"

demo/app/main-view-model.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Observable } from "tns-core-modules/data/observable";
66
import * as fs from "tns-core-modules/file-system";
77
import { isAndroid, isIOS } from "tns-core-modules/platform";
88
import { alert, prompt } from "tns-core-modules/ui/dialogs";
9+
import { UploadMetadata } from "../../src/storage/storage";
910
import { MessagingViewModel } from "./messaging-view-model";
1011

1112
const firebaseWebApi = require("nativescript-plugin-firebase/app");
@@ -314,7 +315,16 @@ export class HelloWorldModel extends Observable {
314315
const storageRef = firebaseWebApi.storage().ref();
315316
const childRef = storageRef.child("uploads/images/telerik-logo-uploaded.png");
316317

317-
childRef.put(fs.File.fromPath(logoPath)).then(
318+
const metadata: UploadMetadata = {
319+
contentType: "demo/test",
320+
contentLanguage: "fr",
321+
customMetadata: {
322+
"foo": "bar",
323+
"foo2": "bar2"
324+
}
325+
};
326+
327+
childRef.put(fs.File.fromPath(logoPath), metadata).then(
318328
uploadedFile => {
319329
console.log("Uploaded! " + JSON.stringify(uploadedFile));
320330
this.set("storageFeedback", "Uploaded!");
@@ -1639,13 +1649,23 @@ export class HelloWorldModel extends Observable {
16391649
const appPath = fs.knownFolders.currentApp().path;
16401650
const logoPath = appPath + "/images/telerik-logo.png";
16411651

1652+
const metadata: UploadMetadata = {
1653+
contentType: "demo/test2",
1654+
contentLanguage: "de",
1655+
customMetadata: {
1656+
"first": "first!",
1657+
"second": "second!"
1658+
}
1659+
};
1660+
16421661
firebaseStorage.uploadFile({
16431662
remoteFullPath: 'uploads/images/telerik-logo-uploaded.png',
16441663
localFile: fs.File.fromPath(logoPath), // use this (a file-system module File object)
16451664
// localFullPath: logoPath, // or this, a full file path
16461665
onProgress: status => {
16471666
console.log("Uploaded fraction: " + status.fractionCompleted + " (" + status.percentageCompleted + "%)");
1648-
}
1667+
},
1668+
metadata
16491669
}).then(
16501670
uploadedFile => {
16511671
alert({

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"firebase-functions": "^2.0.5",
13-
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-10.3.2.tgz",
13+
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-10.3.3.tgz",
1414
"nativescript-theme-core": "^1.0.4",
1515
"nativescript-unit-test-runner": "0.7.0",
1616
"tns-core-modules": "~6.1.1"

docs/STORAGE.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ You can either pass in a full local path to a file, or (as a convenience) use th
5959
// determine the path to a file in the app/res folder
6060
var logoPath = appPath + "/res/telerik-logo.png";
6161

62+
var metadata = {
63+
contentType: "demo/test",
64+
contentLanguage: "fr",
65+
customMetadata: {
66+
"foo": "bar",
67+
"foo2": "bar2"
68+
}
69+
};
70+
6271
// now upload the file with either of the options below:
6372
firebase.storage.uploadFile({
6473
// optional, can be omitted since 6.5.0, and also be passed during init() as 'storageBucket' param so we can cache it (find it in the Firebase console)
@@ -73,7 +82,8 @@ You can either pass in a full local path to a file, or (as a convenience) use th
7382
onProgress: function(status) {
7483
console.log("Uploaded fraction: " + status.fractionCompleted);
7584
console.log("Percentage complete: " + status.percentageCompleted);
76-
}
85+
},
86+
metadata
7787
}).then(
7888
function (uploadedFile) {
7989
console.log("File uploaded: " + JSON.stringify(uploadedFile));
@@ -100,7 +110,15 @@ You can either pass in a full local path to a file, or (as a convenience) use th
100110
const storageRef = firebaseWebApi.storage().ref();
101111
const childRef = storageRef.child("uploads/images/telerik-logo-uploaded.png");
102112

103-
childRef.put(fs.File.fromPath(logoPath)).then(
113+
const metadata = {
114+
contentType: "demo/test",
115+
contentLanguage: "fr",
116+
customMetadata: {
117+
"foo": "bar",
118+
"foo2": "bar2"
119+
}
120+
};
121+
childRef.put(fs.File.fromPath(logoPath), metadata).then(
104122
uploadedFile => console.log("Uploaded! " + JSON.stringify(uploadedFile)),
105123
error => console.log("firebase.doWebUploadFile error: " + error)
106124
);

src/app/storage/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { File } from "tns-core-modules/file-system"
22
import * as firebaseStorage from "../../storage/storage";
3-
import { ListResult, UploadFileResult } from "../../storage/storage";
3+
import { ListResult, UploadFileResult, UploadMetadata } from "../../storage/storage";
44

55
export module storage {
66

@@ -9,6 +9,10 @@ export module storage {
99
totalBytes: number;
1010
}
1111

12+
export interface Metadata {
13+
string: string;
14+
}
15+
1216
export class Reference {
1317

1418
private path: string;
@@ -43,19 +47,26 @@ export module storage {
4347
});
4448
}
4549

50+
getMetadata(): Promise<string> {
51+
return firebaseStorage.getDownloadUrl({
52+
remoteFullPath: this.path
53+
});
54+
}
55+
4656
listAll(): Promise<ListResult> {
4757
return firebaseStorage.listAll({
4858
remoteFullPath: this.path
4959
});
5060
}
5161

52-
public put(data: File | string /* path */, metadata?: any /* ignored */): Promise<UploadTaskSnapshot> {
62+
public put(data: File | string /* path */, metadata?: UploadMetadata): Promise<UploadTaskSnapshot> {
5363
return new Promise((resolve, reject) => {
5464
firebaseStorage.uploadFile({
5565
localFile: data instanceof File ? data : undefined,
5666
localFullPath: !(data instanceof File) ? data : undefined,
5767
remoteFullPath: this.path,
58-
onProgress: progress => console.log(`Upload progress: ${progress.percentageCompleted}% completed`)
68+
onProgress: progress => console.log(`Upload progress: ${progress.percentageCompleted}% completed`),
69+
metadata
5970
}).then((result: UploadFileResult) => {
6071
this.getDownloadURL()
6172
.then(url => {

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "10.3.2",
3+
"version": "10.3.3",
44
"description": "Fire. Base. Firebase!",
55
"main": "firebase",
66
"typings": "index.d.ts",

src/storage/storage.android.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,32 @@ export function uploadFile(arg: UploadFileOptions): Promise<UploadFileResult> {
101101
}
102102
});
103103

104+
let metadata: com.google.firebase.storage.StorageMetadata = null;
105+
if (arg.metadata) {
106+
const metadataBuilder = new com.google.firebase.storage.StorageMetadata.Builder();
107+
if (arg.metadata.cacheControl) {
108+
metadataBuilder.setCacheControl(arg.metadata.cacheControl);
109+
}
110+
if (arg.metadata.contentDisposition) {
111+
metadataBuilder.setContentDisposition(arg.metadata.contentDisposition);
112+
}
113+
if (arg.metadata.contentEncoding) {
114+
metadataBuilder.setContentEncoding(arg.metadata.contentEncoding);
115+
}
116+
if (arg.metadata.contentLanguage) {
117+
metadataBuilder.setContentLanguage(arg.metadata.contentLanguage);
118+
}
119+
if (arg.metadata.contentType) {
120+
metadataBuilder.setContentType(arg.metadata.contentType);
121+
}
122+
if (arg.metadata.customMetadata) {
123+
for (let p in arg.metadata.customMetadata) {
124+
metadataBuilder.setCustomMetadata(p, arg.metadata.customMetadata[p]);
125+
}
126+
}
127+
metadata = metadataBuilder.build();
128+
}
129+
104130
if (arg.localFile) {
105131
if (typeof (arg.localFile) !== "object") {
106132
reject("localFile argument must be a File object; use file-system module to create one");
@@ -109,7 +135,7 @@ export function uploadFile(arg: UploadFileOptions): Promise<UploadFileResult> {
109135

110136
// using 'putFile' (not 'putBytes') so Firebase can infer the mimetype
111137
const localFileUrl = android.net.Uri.fromFile(new java.io.File(arg.localFile.path));
112-
storageReference.putFile(localFileUrl)
138+
storageReference.putFile(localFileUrl, metadata)
113139
.addOnFailureListener(onFailureListener)
114140
.addOnSuccessListener(onSuccessListener)
115141
.addOnProgressListener(onProgressListener);
@@ -137,7 +163,7 @@ export function uploadFile(arg: UploadFileOptions): Promise<UploadFileResult> {
137163
}
138164

139165
const localFileUrl = android.net.Uri.fromFile(new java.io.File(arg.localFullPath));
140-
storageReference.putFile(localFileUrl)
166+
storageReference.putFile(localFileUrl, metadata)
141167
.addOnFailureListener(onFailureListener)
142168
.addOnSuccessListener(onSuccessListener)
143169
.addOnProgressListener(onProgressListener);

0 commit comments

Comments
 (0)