mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-24 04:24:52 +08:00
docs
This commit is contained in:
91
docs/api/storage.md
Normal file
91
docs/api/storage.md
Normal file
@@ -0,0 +1,91 @@
|
||||
|
||||
# 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()
|
||||
Reference in New Issue
Block a user