@@ -85,11 +85,9 @@ public boolean isExternalStorageWritable() {
85
85
}
86
86
87
87
@ ReactMethod
88
- public void downloadFile (final String urlStr ,
89
- final String fbPath ,
88
+ public void downloadFile (final String remotePath ,
90
89
final String localFile ,
91
90
final Callback callback ) {
92
- Log .d (TAG , "downloadFile: " + urlStr + ", " + localFile );
93
91
if (!isExternalStorageWritable ()) {
94
92
Log .w (TAG , "downloadFile failed: external storage not writable" );
95
93
WritableMap error = Arguments .createMap ();
@@ -99,13 +97,9 @@ public void downloadFile(final String urlStr,
99
97
callback .invoke (error );
100
98
return ;
101
99
}
102
- FirebaseStorage storage = FirebaseStorage .getInstance ();
103
- String storageBucket = storage .getApp ().getOptions ().getStorageBucket ();
104
- String storageUrl = "gs://" + storageBucket ;
105
- Log .d (TAG , "Storage url " + storageUrl + fbPath );
100
+ Log .d (TAG , "downloadFile from remote path: " + remotePath );
106
101
107
- StorageReference storageRef = storage .getReferenceFromUrl (storageUrl );
108
- StorageReference fileRef = storageRef .child (fbPath );
102
+ StorageReference fileRef = FirebaseStorage .getInstance ().getReference (remotePath );
109
103
110
104
fileRef .getStream (new StreamDownloadTask .StreamProcessor () {
111
105
@ Override
@@ -182,15 +176,10 @@ public void onFailure(@NonNull Exception exception) {
182
176
}
183
177
184
178
@ ReactMethod
185
- public void downloadUrl (final String javascriptStorageBucket ,
186
- final String path ,
179
+ public void downloadUrl (final String remotePath ,
187
180
final Callback callback ) {
188
- FirebaseStorage storage = FirebaseStorage .getInstance ();
189
- String storageBucket = storage .getApp ().getOptions ().getStorageBucket ();
190
- String storageUrl = "gs://" + storageBucket ;
191
- Log .d (TAG , "Storage url " + storageUrl + path );
192
- final StorageReference storageRef = storage .getReferenceFromUrl (storageUrl );
193
- final StorageReference fileRef = storageRef .child (path );
181
+ Log .d (TAG , "Download url for remote path: " + remotePath );
182
+ final StorageReference fileRef = FirebaseStorage .getInstance ().getReference (remotePath );
194
183
195
184
Task <Uri > downloadTask = fileRef .getDownloadUrl ();
196
185
downloadTask
@@ -200,7 +189,7 @@ public void onSuccess(Uri uri) {
200
189
final WritableMap res = Arguments .createMap ();
201
190
202
191
res .putString ("status" , "success" );
203
- res .putString ("bucket" , storageRef . getBucket ());
192
+ res .putString ("bucket" , FirebaseStorage . getInstance (). getApp (). getOptions (). getStorageBucket ());
204
193
res .putString ("fullPath" , uri .toString ());
205
194
res .putString ("path" , uri .getPath ());
206
195
res .putString ("url" , uri .toString ());
@@ -256,12 +245,10 @@ private WritableMap getMetadataAsMap(StorageMetadata storageMetadata) {
256
245
257
246
// STORAGE
258
247
@ ReactMethod
259
- public void uploadFile (final String urlStr , final String name , final String filepath , final ReadableMap metadata , final Callback callback ) {
260
- FirebaseStorage storage = FirebaseStorage .getInstance ();
261
- StorageReference storageRef = storage .getReferenceFromUrl (urlStr );
262
- StorageReference fileRef = storageRef .child (name );
248
+ public void uploadFile (final String remotePath , final String filepath , final ReadableMap metadata , final Callback callback ) {
249
+ StorageReference fileRef = FirebaseStorage .getInstance ().getReference (remotePath );
263
250
264
- Log .i (TAG , "From file: " + filepath + " to " + urlStr + " with name " + name );
251
+ Log .i (TAG , "Upload file: " + filepath + " to " + remotePath );
265
252
266
253
try {
267
254
Uri file ;
0 commit comments