You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Firebase is a back end platform that offers several services to aid in the development of apps and games, specially the ones that rely on server side infrastructure.
4
4
5
-
Some of its services can be accessed by using RESTful techniques. This repository contains detailed guides and [examples](./examples) explaining how to use those services in your `Adobe AIR ` projects.
5
+
Some of its services can be accessed by using a RESTful approach. This repository contains detailed guides and [examples](./examples) explaining how to use those services in your `Adobe AIR ` projects.
6
6
7
7
You won't need an `ANE` for these guides, all of them work only using `StageWebView`, `URLRequest` and `URLLoader`.
Copy file name to clipboardExpand all lines: auth/README.md
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -206,7 +206,12 @@ Once you have the profile information you might want to save it on an Object tha
206
206
## Obtaining and Refreshing an Access Token
207
207
208
208
By default the `access_token` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
209
-
To obtain or refresh an `access_token` you only need to provide a `refreshToken` from a Sign In request and specify the `grant_type` as `"refresh_token"`.
209
+
To obtain or refresh an `access_token` you only need to provide the following parameters:
210
+
211
+
Name | Description
212
+
---|---
213
+
`refreshToken` | A long encoded String that contains user information. You can obtain it from a Sign In request.
214
+
`grant_type` | Set to: `refresh_token`
210
215
211
216
```actionscript
212
217
private function refreshToken(refreshToken:String):void
Copy file name to clipboardExpand all lines: auth/email/README.md
+30-9Lines changed: 30 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,13 @@ private function errorHandler(event:flash.events.IOErrorEvent):void
35
35
36
36
## Registering a New User (Sign Up)
37
37
38
-
To register a new user you only require to provide a valid formatted Email Address and a non weak Password.
38
+
To register a new user you only require to provide the following parameters:
39
+
40
+
Name | Description
41
+
---|---
42
+
`email` | A valid formatted Email Address.
43
+
`password` | A non weak Password.
44
+
`returnSecureToken` | Set to: `true`
39
45
40
46
```actionscript
41
47
private function register(email:String, password:String):void
@@ -84,7 +90,13 @@ The `refreshToken` is used to get an `access_token` for Auth requests. For more
84
90
85
91
## Verifying Credentials (Sign In)
86
92
87
-
To sign in an user you only require to provide their valid Email Address and Password and the `returnSecureToken` parameter.
93
+
To sign in an user you only require to provide the following parameters:
94
+
95
+
Name | Description
96
+
---|---
97
+
`email` | The user's Email Address.
98
+
`password` | The user's Password.
99
+
`returnSecureToken` | Set to: `true`
88
100
89
101
```actionscript
90
102
private function login(email:String, password:String):void
@@ -135,10 +147,12 @@ The `refreshToken` is used to get an `access_token` for Auth requests. For more
135
147
136
148
## Password Reset
137
149
138
-
To reset a password you only require to provide 2 parameters:
150
+
To reset a password you only require to provide the following parameters:
139
151
140
-
*`email` is the Email Address you want to send the Password recovery email.
141
-
*`requestType` with the value: `PASSWORD_RESET`
152
+
Name | Description
153
+
---|---
154
+
`email` | The Email Address you want to send the Password recovery email.
155
+
`requestType` | Set to: `PASSWORD_RESET`
142
156
143
157
```actionscript
144
158
private function resetPassword(emai:String):void
@@ -185,9 +199,11 @@ This is commonly used in message boards and ecommerce solutions.
185
199
186
200
This method is similar to the Reset Password one, you need to provide the following parameters:
187
201
188
-
*`email` is the email address you want to verify.
189
-
*`requestType` with the value: `EMAIL_VERIFY`
190
-
*`idToken` is a long encoded String that contains user information. You can obtain this String from the response Object in the Sign Up and Sign In methods.
202
+
Name | Description
203
+
---|---
204
+
`email` | The Email Address you want to verify.
205
+
`requestType` | Set to: `EMAIL_VERIFY`
206
+
`idToken` | A long encoded String that contains user information. You can obtain this String from the response in the Sign Up and Sign In methods.
191
207
192
208
```actionscript
193
209
private function verifyEmail(idToken:String, email:String):void
@@ -395,7 +411,12 @@ A successful response will look like the following JSON structure:
395
411
## Obtaining and Refreshing an Access Token
396
412
397
413
By default the `access_token` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
398
-
To obtain or refresh an `access_token` you only need to provide a `refreshToken` from a Sign In request and specify the `grant_type` as `"refresh_token"`.
414
+
To obtain or refresh an `access_token` you only need to provide the following parameters:
415
+
416
+
Name | Description
417
+
---|---
418
+
`refreshToken` | A long encoded String that contains user information. You can obtain it from a Sign In request.
419
+
`grant_type` | Set to: `refresh_token`
399
420
400
421
```actionscript
401
422
private function refreshToken(refreshToken:String):void
Copy file name to clipboardExpand all lines: database/README.md
+2-5Lines changed: 2 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -155,11 +155,10 @@ private function loadNews():void
155
155
private function newsLoaded(event:flash.events.Event):void
156
156
{
157
157
trace(event.currentTarget.data);
158
-
var rawData:Object = JSON.parse(event.currentTarget.data);
159
158
}
160
159
```
161
160
162
-
A simple GET request (the default for `URLRequest`) is enough. Remember to always add `.json` after the name of the node you want to read.
161
+
A simple `GET` request (the default for `URLRequest`) is enough. Remember to always add `.json` after the name of the node you want to read.
163
162
164
163
To load a Private resource use the following code:
165
164
@@ -176,7 +175,6 @@ private function loadSpecialOffers(authToken:String):void
176
175
private function offersLoaded(event:flash.events.Event):void
177
176
{
178
177
trace(event.currentTarget.data);
179
-
var rawData:Object = JSON.parse(event.currentTarget.data);
180
178
}
181
179
```
182
180
@@ -359,7 +357,7 @@ For example, we want that each user has their independent journal that they can
359
357
}
360
358
```
361
359
362
-
When you want to modify or read their journal you need to specify the users's`localId` (known as `uid` inside the rules) and `authToken` as part of the URL.
360
+
When you want to modify or read their journal you need to specify the users `localId` (known as `uid` inside the rules) and `authToken` as part of the URL.
363
361
364
362
```actionscript
365
363
private function loadPrivateJournal(localId:String, authToken:String):void
@@ -374,7 +372,6 @@ private function loadPrivateJournal(localId:String, authToken:String):void
374
372
private function journalLoaded(event:flash.events.Event):void
375
373
{
376
374
trace(event.currentTarget.data);
377
-
var rawData:Object = JSON.parse(event.currentTarget.data);
Copy file name to clipboardExpand all lines: storage/README.md
+46-32Lines changed: 46 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Files are stored the same way as in your personal computer, using a tree hierarc
6
6
7
7
It is strongly recommended to avoid the use of special characters when naming files and folders.
8
8
9
-
You need special care for the slash character `(/)`. I recommend using this helper function to URL encode them:
9
+
You will need special care for the slash character `(/)`. I recommend using this helper function to URL encode them:
10
10
11
11
```actionscript
12
12
private function formatUrl(url:String):String
@@ -84,11 +84,10 @@ service firebase.storage {
84
84
}
85
85
```
86
86
87
-
## Uploading a File
87
+
## Prerequisites
88
88
89
-
To upload a file you require to send it as a `ByteArray`. The following snippets show the most common scenarios.
90
89
91
-
All of the examples use the following `Event.COMPLETE` and `IOErrorEvent.IOERROR` listeners.
90
+
Since Firebase returns useful error information we will use the following `Event.COMPLETE` and `IOErrorEvent.IOERROR` listeners in all of our requests.
92
91
93
92
```actionscript
94
93
private function uploadComplete(event:flash.events.Event):void
@@ -102,9 +101,11 @@ private function errorHandler(event:flash.events.Event):void
102
101
}
103
102
```
104
103
105
-
If you upload the same file to the same location, it will be replaced with new metadata.
104
+
## Uploading from a fixed location
106
105
107
-
### Uploading from a fixed location
106
+
To upload a file you require to send it as a `ByteArray`. The following snippets show the most common scenarios.
107
+
108
+
If you upload the same file to the same location, it will be replaced with new metadata.
108
109
109
110
In this example we are uploading a file from a predefined location. A common example is syncing a save game after a game session:
110
111
@@ -119,7 +120,7 @@ private function uploadFile():void
119
120
fileStream.readBytes(bytes);
120
121
fileStream.close();
121
122
122
-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/"+"savegames%2F"+"savegame.data");
123
+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
123
124
request.method = URLRequestMethod.POST;
124
125
request.data = bytes;
125
126
request.contentType = "text/plain";
@@ -156,9 +157,9 @@ Your new file and a `savegames` folder will instantly appear in the Storage sect
156
157
157
158
The `contentType` doesn't need to be accurate, but it is recommended to set it properly.
158
159
159
-
###Uploading with Auth
160
+
## Uploading with Auth
160
161
161
-
Authorizing requests for Firebase Storage is a bit different than in Firebase Database. Instead of adding an `auth` parameter in the URL with the `authToken`, we add it into an `URLRequestHeader`.
162
+
Authorizing requests for Firebase Storage is a bit different than in Firebase Database. Instead of adding an `auth` parameter in the URL with the `authToken`, we add it into a header.
162
163
163
164
```actionscript
164
165
private function uploadFile(authToken:String):void
@@ -173,7 +174,7 @@ private function uploadFile(authToken:String):void
173
174
174
175
var header:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
175
176
176
-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/"+"savegames%2F"+"savegame.data");
177
+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
177
178
request.method = URLRequestMethod.POST;
178
179
request.data = bytes;
179
180
request.contentType = "text/plain";
@@ -220,7 +221,7 @@ private function deleteFile():void
220
221
{
221
222
var header:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "DELETE");
222
223
223
-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data");
224
+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
224
225
request.method = URLRequestMethod.POST;
225
226
request.requestHeaders.push(header);
226
227
@@ -233,15 +234,17 @@ private function deleteFile():void
233
234
234
235
A successful response will return an [empty String](https://cloud.google.com/storage/docs/json_api/v1/objects/delete).
235
236
236
-
Use the following snippet if you want to delete the same file using authentication:
237
+
## Deleting a File with Auth
238
+
239
+
To delete a file with authentication you only need to provide an `authToken` in the `Authorization` header and the file path in a `DELETE` request.
237
240
238
241
```actionscript
239
242
private function deleteFile(authToken:String):void
240
243
{
241
244
var header:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "DELETE");
242
245
var header2:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
243
246
244
-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data");
247
+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
245
248
request.method = URLRequestMethod.POST;
246
249
request.requestHeaders.push(header);
247
250
request.requestHeaders.push(header2);
@@ -255,7 +258,7 @@ private function deleteFile(authToken:String):void
255
258
256
259
## Updating Metadata
257
260
258
-
To modify the metadata generated after your upload a file you will only require to indicate which fields do you need to update. This is very similar as updating the Firebase Database data.
261
+
To modify the metadata generated after your upload a file you will only require to `JSON` encode which fields do you need to update and send them in a `PATCH` request. This is very similar as updating the Firebase Database data.
259
262
260
263
Click [here](https://firebase.google.com/docs/storage/web/file-metadata) for a list of all the fields that can be modified. In the following example we are going to change the `contentType`.
261
264
@@ -302,19 +305,23 @@ A successful response will look like the following JSON structure:
302
305
}
303
306
```
304
307
305
-
Use the following snippet if you want to update the same file using authentication:
308
+
## Updating Metadata with Auth
309
+
310
+
To update metadata with authentication you need to provide an `authToken` in the `Authorization` header.
311
+
312
+
You will also require to `JSON` encode which fields do you need to update and send them in a `PATCH` request.
306
313
307
314
```actionscript
308
-
private function updateMetadata():void
315
+
private function updateMetadata(authToken:String):void
309
316
{
310
317
var myObject:Object = new Object();
311
318
myObject.contentType = "application/binary";
312
319
313
320
var header:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "PATCH");
314
321
var header2:URLRequestHeader = new URLRequestHeader("Content-Type", "application/json");
315
-
var header3:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+profile.authToken);
322
+
var header3:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
316
323
317
-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/"+"savegames%2F"+"savegame.data");
324
+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
318
325
request.method = URLRequestMethod.POST;
319
326
request.data = JSON.stringify(myObject);
320
327
request.requestHeaders.push(header);
@@ -328,11 +335,16 @@ private function updateMetadata():void
328
335
}
329
336
```
330
337
331
-
## Downloading Files
338
+
## Downloading a File
332
339
333
340
To download files from your Firebase Storage bucket you only require to send a `GET` request with the full path of the file and the parameter `alt=media`.
341
+
You will also require the followinv values from the `JSON` structure.
334
342
335
-
We are going to use the following JSON structure as our example:
343
+
Name | Description
344
+
---|---
345
+
`name` | The path of the file including its name.
346
+
`bucket` | Your Firebase Project ID plus the `appspot.com` domain.
347
+
`downloadTokens` | A String used for downloading private files.
336
348
337
349
```json
338
350
{
@@ -355,30 +367,30 @@ We are going to use the following JSON structure as our example:
355
367
356
368
There are several ways to download files using the AIR runtime, we are going to use the easiest one: `navigateToURL()`.
357
369
358
-
Use the following code to download a `public` file:
370
+
The following example downloads a `public` file:
359
371
360
372
```actionscript
361
373
private function downloadFile():void
362
374
{
363
-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data?alt=media");
375
+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data"+"?alt=media");
364
376
navigateToURL(request);
365
377
}
366
378
```
367
379
368
-
Use the following code to download a `private` file:
380
+
## Downloading a Private File
381
+
382
+
Downloading `private` files doesn't require the `Authorization` header. You only require to provide the `token` parameter and the file path.
383
+
384
+
The `token` parameter is the `downloadTokens` value from the `JSON` response when you upload a file.
369
385
370
386
```actionscript
371
387
private function downloadFile(downloadTokens:String):void
372
388
{
373
-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data?alt=media&token="+downloadTokens);
389
+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data"+"?alt=media&token="+downloadTokens);
374
390
navigateToURL(request);
375
391
}
376
392
```
377
393
378
-
Don't forget to encode the slash character from `(/)` to `%2F`.
379
-
380
-
The `token` parameter refers to the `downloadTokens` value from the JSON response when you upload a file.
381
-
382
394
## Downloading Metadata
383
395
384
396
You can download the information of any file in JSON format without downloading the file itself.
@@ -388,7 +400,7 @@ To download the metadata of a `public` file you only require to send a `GET` req
388
400
```actionscript
389
401
private function downloadMetadata():void
390
402
{
391
-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data");
403
+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
@@ -401,14 +413,16 @@ private function metadataLoaded(event:flash.events.Event):void
401
413
}
402
414
```
403
415
404
-
Use the following snippet to download the metadata of a `private` file:
416
+
## Downloading Private Metadata
417
+
418
+
To download metadata from `private` files you require to provide an `authToken` in the `Authorization` header.
405
419
406
420
```actionscript
407
421
private function downloadMetadata(authToken:String):void
408
422
{
409
423
var header:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
410
424
411
-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2Fsavegame.data");
425
+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+"savegame.data");
412
426
request.method = URLRequestMethod.POST;
413
427
request.requestHeaders.push(header);
414
428
@@ -473,7 +487,7 @@ private function uploadPersonalFile(authToken:String, localId:String):void
473
487
474
488
var header:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
475
489
476
-
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/"+"savegames%2F"+localId+"%2Fsavegame.data");
490
+
var request:URLRequest = new URLRequest("https://firebasestorage.googleapis.com/v0/b/<YOUR-PROJECT-ID>.appspot.com/o/savegames%2F"+localId+"%2F"+"savegame.data");
0 commit comments