@@ -85,11 +85,9 @@ public boolean isExternalStorageWritable() {
8585 }
8686
8787 @ ReactMethod
88- public void downloadFile (final String urlStr ,
89- final String fbPath ,
88+ public void downloadFile (final String remotePath ,
9089 final String localFile ,
9190 final Callback callback ) {
92- Log .d (TAG , "downloadFile: " + urlStr + ", " + localFile );
9391 if (!isExternalStorageWritable ()) {
9492 Log .w (TAG , "downloadFile failed: external storage not writable" );
9593 WritableMap error = Arguments .createMap ();
@@ -99,13 +97,9 @@ public void downloadFile(final String urlStr,
9997 callback .invoke (error );
10098 return ;
10199 }
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 );
106101
107- StorageReference storageRef = storage .getReferenceFromUrl (storageUrl );
108- StorageReference fileRef = storageRef .child (fbPath );
102+ StorageReference fileRef = FirebaseStorage .getInstance ().getReference (remotePath );
109103
110104 fileRef .getStream (new StreamDownloadTask .StreamProcessor () {
111105 @ Override
@@ -182,15 +176,10 @@ public void onFailure(@NonNull Exception exception) {
182176 }
183177
184178 @ ReactMethod
185- public void downloadUrl (final String javascriptStorageBucket ,
186- final String path ,
179+ public void downloadUrl (final String remotePath ,
187180 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 );
194183
195184 Task <Uri > downloadTask = fileRef .getDownloadUrl ();
196185 downloadTask
@@ -200,7 +189,7 @@ public void onSuccess(Uri uri) {
200189 final WritableMap res = Arguments .createMap ();
201190
202191 res .putString ("status" , "success" );
203- res .putString ("bucket" , storageRef . getBucket ());
192+ res .putString ("bucket" , FirebaseStorage . getInstance (). getApp (). getOptions (). getStorageBucket ());
204193 res .putString ("fullPath" , uri .toString ());
205194 res .putString ("path" , uri .getPath ());
206195 res .putString ("url" , uri .toString ());
@@ -256,12 +245,10 @@ private WritableMap getMetadataAsMap(StorageMetadata storageMetadata) {
256245
257246 // STORAGE
258247 @ 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 );
263250
264- Log .i (TAG , "From file: " + filepath + " to " + urlStr + " with name " + name );
251+ Log .i (TAG , "Upload file: " + filepath + " to " + remotePath );
265252
266253 try {
267254 Uri file ;
0 commit comments