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

Commit 8dc6630

Browse files
#43 Document uploading? Firebase Storage!
1 parent 7367221 commit 8dc6630

File tree

15 files changed

+716
-52
lines changed

15 files changed

+716
-52
lines changed

CHANGELOG.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<table>
2+
<tr>
3+
<td><img src="docs/images/firebase.png" width="116px" height="32px" alt="Firebase"/></td>
4+
<td>Changelog</td>
5+
</tr>
6+
</table>
7+
8+
Click the version numbers for full changelogs or just satisfy your curiosity by looking at the highlights.
9+
10+
## [3.4.0]((https://github.com/EddyVerbruggen/nativescript-plugin-firebase/compare/3.3.0...3.4.0)) (2016, July 7)
11+
12+
### SDK versions
13+
If version numbers changed clean your platform folders to avoid build errors.
14+
15+
- iOS: 3.3.x
16+
- Android: 9.2.0
17+
18+
### New
19+
- [#43](#43) Storage ([docs](docs/STORAGE.md))
20+
- [#66](#66) Added `iOSSimulatorFlush` for a known iOS emulator issue with `invalid_token`
21+
22+
### Fixes
23+
- [#69](#69) Fix `onAuthStateChanged` feature on `init`
24+
25+
## [3.3.0]((https://github.com/EddyVerbruggen/nativescript-plugin-firebase/compare/3.2.0...3.3.0)) (2016, June 26)
26+
27+
### SDK versions
28+
If version numbers changed clean your platform folders to avoid build errors.
29+
30+
- iOS: 3.2.x
31+
- Android: 9.0.2
32+
33+
### New
34+
- [#54](#54) FCM Messaging / Push Notifications ([docs](docs/MESSAGING.md))
35+
36+
37+
38+
## [3.2.0]((https://github.com/EddyVerbruggen/nativescript-plugin-firebase/compare/3.1.0...3.2.0)) (2016, June 19)
39+
40+
### SDK versions
41+
If version numbers changed clean your platform folders to avoid build errors.
42+
43+
- iOS: 3.2.0
44+
- Android: 9.0.2
45+
46+
### New
47+
- [#56](#56) Remote Config ([docs](docs/REMOTECONFIG.md))
48+
49+
## [3.1.0]((https://github.com/EddyVerbruggen/nativescript-plugin-firebase/compare/3.0.0...3.1.0)) (2016, June 17)
50+
51+
### SDK versions
52+
If version numbers changed clean your platform folders to avoid build errors.
53+
54+
- iOS: 3.2.0
55+
- Android: 9.0.0
56+
57+
### New
58+
- [#49](#49) Custom Authentication ([docs](docs/AUTHENTICATION.md#custom-login))
59+
60+
61+
## [3.0.0]((https://github.com/EddyVerbruggen/nativescript-plugin-firebase/compare/2.1.8...3.0.0)) (2016, May 26)
62+
63+
### SDK versions
64+
If version numbers changed clean your platform folders to avoid build errors.
65+
66+
- iOS: 3.2.0
67+
- Android: 9.0.0
68+
69+
### New
70+
- [#34](#34) Support new Firebase 3 release

README.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# NativeScript Firebase plugin
22

3-
<img src="docs/images/firebase.png" width="154px" height="43px" alt="Firebase"/><br/>
3+
<img src="docs/images/firebase.png" width="116px" height="32px" alt="Firebase"/><br/>
44
Google's realtime app platform (Database, Authentication, Configuration, Notifications) [firebase.google.com](https://firebase.google.com/)
55

6-
### Use when
7-
* you need to store JSON data in the cloud (but don't want to loose data when the device is offline),
8-
* you want to sync that data to other devices and platforms,
9-
* you want to optionally protect that data by having users log in,
10-
* you want to update clients at the moment the data changes (think chat and multiplayer games),
11-
* you want an easy way to remotely configure app features,
12-
* you want push notifications.
6+
## Features
7+
For readability the supported features have been moved to their own README's:
8+
9+
* Setup and troubleshooting (continue reading below)
10+
* [Realtime Database](docs/DATABASE.md)
11+
* [Authentication](docs/AUTHENTICATION.md)
12+
* [Remote Config](docs/REMOTECONFIG.md)
13+
* [Cloud Messaging](docs/MESSAGING.md)
14+
* [Storage ](docs/STORAGE.md)
1315

1416
## Prerequisites
1517
Head on over to [https://console.firebase.google.com/](https://console.firebase.google.com/) and sign up for a free account.
@@ -112,15 +114,6 @@ firebase.init({
112114
);
113115
```
114116

115-
## Features
116-
For readability the supported features have been moved to their own README's:
117-
118-
* [Realtime Database](docs/DATABASE.md)
119-
* [Authentication](docs/AUTHENTICATION.md)
120-
* [Remote Config](docs/REMOTECONFIG.md)
121-
* [Cloud Messaging](docs/MESSAGING.md)
122-
123-
124117
## Known issues on iOS
125118
On the simulator you may see this message if you have more than one app with the Firebase SDK ever installed:
126119

docs/AUTHENTICATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<table>
22
<tr>
3-
<td><img src="images/firebase.png" width="154px" height="43px" alt="Firebase"/></td>
3+
<td><img src="images/firebase.png" width="116px" height="32px" alt="Firebase"/></td>
44
<td>Authentication</td>
55
</tr>
66
</table>

docs/DATABASE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<table>
22
<tr>
3-
<td><img src="images/firebase.png" width="154px" height="43px" alt="Firebase"/></td>
3+
<td><img src="images/firebase.png" width="116px" height="32px" alt="Firebase"/></td>
44
<td>Database</td>
55
</tr>
66
</table>

docs/MESSAGING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<table>
22
<tr>
3-
<td><img src="images/firebase.png" width="154px" height="43px" alt="Firebase"/></td>
3+
<td><img src="images/firebase.png" width="116px" height="32px" alt="Firebase"/></td>
44
<td>Cloud Messaging</td>
55
</tr>
66
</table>

docs/REMOTECONFIG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<table>
22
<tr>
3-
<td><img src="images/firebase.png" width="154px" height="43px" alt="Firebase"/></td>
3+
<td><img src="images/firebase.png" width="116px" height="32px" alt="Firebase"/></td>
44
<td>Remote Config</td>
55
</tr>
66
</table>

docs/STORAGE.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<table>
2+
<tr>
3+
<td><img src="images/firebase.png" width="116px" height="32px" alt="Firebase"/></td>
4+
<td>Storage</td>
5+
</tr>
6+
</table>
7+
8+
## Enabling Storage
9+
Since plugin version 3.4.0 you can use Firebase _Storage_ features.
10+
11+
_Storage_ lets you upload and download files to/from Google Cloud Storage which is connected to your Firebase instance.
12+
13+
To enable support for Remote Config you need to manually adjust
14+
[Podfile](../platforms/ios/Podfile) and [include.gradle](../platforms/android/include.gradle).
15+
16+
Just uncomment the relevant lines (one for each platform) to add the SDK's to your app.
17+
18+
### Setting the storage bucket
19+
You need to tell Firebase what your storage bucket is. You can retrieve it
20+
from the Firebase console by pressing 'Storage' in the menu.
21+
22+
You can either pass it to the `init()` function as shown below,
23+
or pass it as a property any time you're using a storage feature.
24+
In theory the former is a little more efficient because it's cached by the plugin.
25+
26+
```js
27+
firebase.init({
28+
storageBucket: 'gs://n-plugin-test.appspot.com'
29+
// any other options
30+
});
31+
```
32+
33+
## Functions
34+
35+
### uploadFile
36+
You can either pass in a full local path to a file, or (as a convenience) use the `file-system` module that comes shipped with {N} as standard.
37+
38+
```js
39+
// init the file-system module
40+
var fs = require("file-system");
41+
42+
// grab a reference to the app folder
43+
var appPath = fs.knownFolders.currentApp().path;
44+
45+
// determine the path to a file in the app/res folder
46+
var logoPath = appPath + "/res/telerik-logo.png";
47+
48+
// now upload the file with either of the options below:
49+
firebase.uploadFile({
50+
// optional, can also be passed during init() as 'storageBucket' param so we can cache it (find it in the Firebase console)
51+
bucket: 'gs://n-plugin-test.appspot.com',
52+
// the full path of the file in your Firebase storage (folders will be created)
53+
remoteFullPath: 'uploads/images/telerik-logo-uploaded.png',
54+
// option 1: a file-system module File object
55+
localFile: fs.File.fromPath(logoPath),
56+
// option 2: a full file path (ignored if 'localFile' is set)
57+
localFullPath: logoPath
58+
}).then(
59+
function (uploadedFile)
60+
console.log("File uploaded: " + JSON.stringify(uploadedFile));
61+
},
62+
function (error) {
63+
console.log("File upload error: " + error);
64+
};
65+
);
66+
```
67+
68+
### downloadFile
69+
As with `uploadFile` you can either pass in a full local path to a file, or (as a convenience) use the `file-system` module that comes shipped with {N} as standard.
70+
71+
In this example we'll download the previously uploaded file to a certain path on the local filesystem.
72+
73+
```js
74+
// init the file-system module
75+
var fs = require("file-system");
76+
77+
// let's first determine where we'll create the file using the 'file-system' module
78+
var documents = fs.knownFolders.documents();
79+
var logoPath = documents.path + "/telerik-logo-downloaded.png";
80+
81+
// this will create or overwrite a local file in the app's documents folder
82+
var localLogoFile = documents.getFile("telerik-logo-downloaded.png");
83+
84+
// now download the file with either of the options below:
85+
firebase.downloadFile({
86+
// optional, can also be passed during init() as 'storageBucket' param so we can cache it
87+
bucket: 'gs://n-plugin-test.appspot.com',
88+
// the full path of an existing file in your Firebase storage
89+
remoteFullPath: 'uploads/images/telerik-logo-uploaded.png',
90+
// option 1: a file-system module File object
91+
localFile: fs.File.fromPath(logoPath),
92+
// option 2: a full file path (ignored if 'localFile' is set)
93+
localFullPath: logoPath
94+
}).then(
95+
function (uploadedFile)
96+
console.log("File downloaded to the requested location");
97+
},
98+
function (error) {
99+
console.log("File download error: " + error);
100+
};
101+
);
102+
```
103+
104+
### getDownloadUrl
105+
If you just want to know the remote URL of a file in remote storage so you can either share it or download the file by any other means than `downloadFile` then use this method.
106+
107+
In this example we'll determine the remote URL of the previously uploaded file.
108+
109+
```js
110+
firebase.getDownloadUrl({
111+
// optional, can also be passed during init() as 'storageBucket' param so we can cache it
112+
bucket: 'gs://n-plugin-test.appspot.com',
113+
// the full path of an existing file in your Firebase storage
114+
remoteFullPath: 'uploads/images/telerik-logo-uploaded.png'
115+
}).then(
116+
function (url)
117+
console.log("Remote URL: " + url);
118+
},
119+
function (error) {
120+
console.log("Error: " + error);
121+
};
122+
);
123+
```

docs/images/firebase.png

-10.2 KB
Loading

firebase-common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ firebase.QueryRangeType = {
2626
};
2727

2828
firebase.instance = null;
29+
firebase.storage = null;
2930
firebase.firebaseRemoteConfig = null;
3031
firebase.authStateListeners = [];
3132
firebase._receivedNotificationCallback = null;

0 commit comments

Comments
 (0)