Returning null as downloadUrl in upload task (#1620)

solves: #1591 using the first solution:

> 1. Still consider the invocation a success, providing downloadURL as null.

Can some maintainer help me with the new test case? I need a file with permission to upload but not to download.
This commit is contained in:
Felipe Waku
2018-10-19 20:55:01 -03:00
committed by Michael Diarmid
parent 6684d5e739
commit bf3f5001a0
2 changed files with 50 additions and 20 deletions

View File

@@ -564,29 +564,20 @@ public class RNFirebaseStorage extends ReactContextBaseJavaModule {
taskSnapshot
.getStorage()
.getDownloadUrl()
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@Nonnull Exception e) {
int errorCode = ((StorageException) e).getErrorCode();
if (errorCode == StorageException.ERROR_NOT_AUTHORIZED) {
WritableMap resp = getRespAsMap(taskSnapshot, null);
listener.onSuccess(resp);
}
}
})
.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri downloadUrl) {
WritableMap resp = Arguments.createMap();
resp.putDouble("bytesTransferred", taskSnapshot.getBytesTransferred());
resp.putString("downloadURL", downloadUrl.toString());
StorageMetadata d = taskSnapshot.getMetadata();
if (d != null) {
WritableMap metadata = getMetadataAsMap(d);
resp.putMap("metadata", metadata);
}
resp.putString(
"ref",
taskSnapshot
.getStorage()
.getPath()
);
resp.putString("state", RNFirebaseStorage.this.getTaskStatus(taskSnapshot.getTask()));
resp.putDouble("totalBytes", taskSnapshot.getTotalByteCount());
WritableMap resp = getRespAsMap(taskSnapshot, downloadUrl.toString());
listener.onSuccess(resp);
}
});
@@ -595,6 +586,29 @@ public class RNFirebaseStorage extends ReactContextBaseJavaModule {
}
}
private WritableMap getRespAsMap(final UploadTask.TaskSnapshot taskSnapshot, final String downloadUrl) {
WritableMap resp = Arguments.createMap();
resp.putDouble("bytesTransferred", taskSnapshot.getBytesTransferred());
resp.putString("downloadURL", downloadUrl);
StorageMetadata d = taskSnapshot.getMetadata();
if (d != null) {
WritableMap metadata = getMetadataAsMap(d);
resp.putMap("metadata", metadata);
}
resp.putString(
"ref",
taskSnapshot
.getStorage()
.getPath()
);
resp.putString("state", RNFirebaseStorage.this.getTaskStatus(taskSnapshot.getTask()));
resp.putDouble("totalBytes", taskSnapshot.getTotalByteCount());
return resp;
}
/**
* Converts storageMetadata into a map
*