Open vikas-jain-plutus opened 4 years ago
// execute the upload private static void performUpload(Uri file, final String type, final OnUploadedCallback callback) { // public storage folder StorageReference storageReference; if (StringUtils.isValid(ChatManager.Configuration.storageBucket)) { storageReference = FirebaseStorage.getInstance() .getReferenceFromUrl(ChatManager.Configuration.storageBucket) .child("public"); } else { storageReference = FirebaseStorage.getInstance() .getReference() .child("public"); }
// random uid.
// this is used to generate an unique folder in which
// upload the file to preserve the filename
final String uuid = UUID.randomUUID().toString();
// upload to /public/images/uuid/file.ext
StorageReference riversRef = storageReference.child(type.toString() + "/" + uuid + "/" +
file.getLastPathSegment());
Log.d(TAG, "riversRef ==" + riversRef);
UploadTask uploadTask = riversRef.putFile(file);
// Register observers to listen for when the download is done or if it fails
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
Log.e(TAG, "addOnFailureListener.onFailure: " + exception.getMessage());
callback.onUploadFailed(exception);
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
Log.d(TAG, "Upload is " + progress + "% done");
int currentProgress = (int) progress;
callback.onProgress(currentProgress);
}
}).addOnPausedListener(new OnPausedListener<UploadTask.TaskSnapshot>() {
@Override
public void onPaused(UploadTask.TaskSnapshot taskSnapshot) {
System.out.println("Upload is paused");
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size,
// content-type, and download URL.
Uri downloadUrl = taskSnapshot.getUploadSessionUri();
Log.d(TAG, "addOnFailureListener.onSuccess - downloadUrl: " + downloadUrl);
callback.onUploadSuccess(uuid, downloadUrl, type);
}
});
}
When I am using implementation 'com.google.firebase:firebase-storage:11.8.0' App gets crashed on this line with below error... storageReference = FirebaseStorage.getInstance() .getReference() .child("public");
Facing issue while Image uploading.