Skip to content

Commit 331f06c

Browse files
committed
Updates to README and storage
1 parent d74e5f1 commit 331f06c

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,47 @@ storageRef.downloadUrl()
589589
})
590590
```
591591

592+
#### download()
593+
594+
It's possible to download remote files as well. The `download()` method will take a remote file and download and save it to the user's device. It is implemented on the `storageRef`:
595+
596+
```javascript
597+
const storageRef = data.firestack.storage.ref('photos/photo.jpg');
598+
const localPath = `downloadedFile.jpg`;
599+
storageRef.download(localPath, (msg) => {
600+
// downloading state callback
601+
})
602+
.then(res => {
603+
// res contains details about the downloaded file
604+
})
605+
.catch(err => {
606+
// error contains any errors in downloading
607+
});
608+
```
609+
610+
The method accepts a callback that gets called with any download events:
611+
612+
* download_progress ({eventName: 'download_progress', progress: float });
613+
* download_paused ({eventName: 'download_paused'})
614+
* download_resumed ({eventName: 'download_resumed'})
615+
616+
As helpful constants, Firestack exports a few storage constants on the `firestack.constants` getter:
617+
618+
* MAIN_BUNDLE_PATH
619+
* CACHES_DIRECTORY_PATH
620+
* DOCUMENT_DIRECTORY_PATH
621+
* EXTERNAL_DIRECTORY_PATH
622+
* EXTERNAL_STORAGE_DIRECTORY_PATH
623+
* TEMP_DIRECTORY_PATH
624+
* LIBRARY_DIRECTORY_PATH
625+
626+
And we also export the filetype constants as well:
627+
628+
* FILETYPE_REGULAR
629+
* FILETYPE_DIRECTORY
630+
631+
> Note: this idea comes almost directory from [react-native-fs](https://github.com/johanneslumpe/react-native-fs), so we don't claim credit for coming up with this fantastic idea.
632+
592633
### Realtime Database
593634

594635
The native Firebase JavaScript library provides a featureful realtime database that works out of the box. Firestack provides an attribute to interact with the database without needing to configure the JS library.

android/src/main/java/io/fullstack/firestack/FirestackStorage.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package io.fullstack.firestack;
22

3+
import android.os.Environment;
4+
import android.os.StatFs;
35
import android.content.Context;
46
import android.util.Log;
57
import java.util.Map;
8+
import java.util.HashMap;
69
import java.io.File;
710
import java.io.FileInputStream;
811
import java.io.InputStream;
@@ -41,6 +44,17 @@
4144
class FirestackStorageModule extends ReactContextBaseJavaModule {
4245

4346
private static final String TAG = "FirestackStorage";
47+
private static final String DocumentDirectoryPath = "DOCUMENT_DIRECTORY_PATH";
48+
private static final String ExternalDirectoryPath = "EXTERNAL_DIRECTORY_PATH";
49+
private static final String ExternalStorageDirectoryPath = "EXTERNAL_STORAGE_DIRECTORY_PATH";
50+
private static final String PicturesDirectoryPath = "PICTURES_DIRECTORY_PATH";
51+
private static final String TemporaryDirectoryPath = "TEMPORARY_DIRECTORY_PATH";
52+
private static final String CachesDirectoryPath = "CACHES_DIRECTORY_PATH";
53+
private static final String DocumentDirectory = "DOCUMENT_DIRECTORY_PATH";
54+
55+
private static final String FileTypeRegular = "FILETYPE_REGULAR";
56+
private static final String FileTypeDirectory = "FILETYPE_DIRECTORY";
57+
4458

4559
private Context context;
4660
private ReactContext mReactContext;
@@ -186,4 +200,34 @@ public void onPaused(UploadTask.TaskSnapshot taskSnapshot) {
186200
callback.invoke(err);
187201
}
188202
}
203+
204+
// Comes almost directory from react-native-fs
205+
@Override
206+
public Map<String, Object> getConstants() {
207+
final Map<String, Object> constants = new HashMap<>();
208+
209+
constants.put(DocumentDirectory, 0);
210+
constants.put(DocumentDirectoryPath, this.getReactApplicationContext().getFilesDir().getAbsolutePath());
211+
constants.put(TemporaryDirectoryPath, null);
212+
constants.put(PicturesDirectoryPath, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
213+
constants.put(CachesDirectoryPath, this.getReactApplicationContext().getCacheDir().getAbsolutePath());
214+
constants.put(FileTypeRegular, 0);
215+
constants.put(FileTypeDirectory, 1);
216+
217+
File externalStorageDirectory = Environment.getExternalStorageDirectory();
218+
if (externalStorageDirectory != null) {
219+
constants.put(ExternalStorageDirectoryPath, externalStorageDirectory.getAbsolutePath());
220+
} else {
221+
constants.put(ExternalStorageDirectoryPath, null);
222+
}
223+
224+
File externalDirectory = this.getReactApplicationContext().getExternalFilesDir(null);
225+
if (externalDirectory != null) {
226+
constants.put(ExternalDirectoryPath, externalDirectory.getAbsolutePath());
227+
} else {
228+
constants.put(ExternalDirectoryPath, null);
229+
}
230+
231+
return constants;
232+
}
189233
}

0 commit comments

Comments
 (0)