92 lines
2.0 KiB
Markdown
92 lines
2.0 KiB
Markdown
|
|
||
|
# Storage
|
||
|
|
||
|
RNFirebase mimics the [Web Firebase SDK Storage](https://firebase.google.com/docs/storage/web/start), whilst
|
||
|
providing some iOS and Android specific functionality.
|
||
|
|
||
|
All Storage operations are accessed via `storage()`.
|
||
|
|
||
|
## Uploading files
|
||
|
|
||
|
### Simple
|
||
|
|
||
|
```javascript
|
||
|
firebase.storage()
|
||
|
.ref('/files/1234')
|
||
|
.putFile('/path/to/file/1234')
|
||
|
.then(uploadedFile => {
|
||
|
//success
|
||
|
})
|
||
|
.catch(err => {
|
||
|
//Error
|
||
|
});
|
||
|
```
|
||
|
|
||
|
### Listen to upload state
|
||
|
|
||
|
```javascript
|
||
|
const unsubscribe = firebase.storage()
|
||
|
.ref('/files/1234')
|
||
|
.putFile('/path/to/file/1234')
|
||
|
.on('state_changed', snapshot => {
|
||
|
//Current upload state
|
||
|
}, err => {
|
||
|
//Error
|
||
|
unsubscribe();
|
||
|
}, uploadedFile => {
|
||
|
//Success
|
||
|
unsubscribe();
|
||
|
});
|
||
|
```
|
||
|
|
||
|
## Downloading files
|
||
|
|
||
|
### Simple
|
||
|
|
||
|
```javascript
|
||
|
firebase.storage()
|
||
|
.ref('/files/1234')
|
||
|
.downloadFile('/path/to/save/file')
|
||
|
.then(downloadedFile => {
|
||
|
//success
|
||
|
})
|
||
|
.catch(err => {
|
||
|
//Error
|
||
|
});
|
||
|
```
|
||
|
|
||
|
### Listen to download state
|
||
|
|
||
|
```javascript
|
||
|
const unsubscribe = firebase.storage()
|
||
|
.ref('/files/1234')
|
||
|
.downloadFile('/path/to/save/file')
|
||
|
.on('state_changed', snapshot => {
|
||
|
//Current download state
|
||
|
}, err => {
|
||
|
//Error
|
||
|
unsubscribe();
|
||
|
}, downloadedFile => {
|
||
|
//Success
|
||
|
unsubscribe();
|
||
|
});
|
||
|
```
|
||
|
|
||
|
## TODO
|
||
|
|
||
|
There are a few methods which have not yet been implemented for Storage:
|
||
|
|
||
|
### Reference
|
||
|
- put()
|
||
|
- putString()
|
||
|
|
||
|
### UploadTask
|
||
|
- cancel()
|
||
|
- pause()
|
||
|
- resume()
|
||
|
|
||
|
### DownloadTask
|
||
|
- cancel()
|
||
|
- pause()
|
||
|
- resume()
|