taskSnapshot.getDownloadUrl() method not working

后端 未结 23 760
有刺的猬
有刺的猬 2020-12-08 08:03
private void uploadImageToFirebaseStorage() {
    StorageReference profileImageRef =
        FirebaseStorage.getInstance().getReference(\"profilepics/\" + System.cur         


        
23条回答
  •  囚心锁ツ
    2020-12-08 08:59

    My Google Firebase Plugins in build.gradle(Module: app):

    implementation 'com.firebaseui:firebase-ui-database:3.3.1'
    implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    

    build.gradle(Project):

     classpath 'com.google.gms:google-services:3.2.1'
    

    My upload() function and fetching uploaded data from Firebase storage :

    private void upload() {
        if (filePath!=null) {
            final ProgressDialog progressDialog = new ProgressDialog(this);
            progressDialog.setTitle("Uploading...");
            progressDialog.show();
    
            final StorageReference ref = storageReference.child(new StringBuilder("images/").append(UUID.randomUUID().toString()).toString());
            uploadTask = ref.putFile(filePath);
    
            Task urlTask = uploadTask.continueWithTask(new Continuation>() {
                @Override
                public Task then(@NonNull Task task) throws Exception {
                    if (!task.isSuccessful()) {
                        throw task.getException();
                    }
    
                    return ref.getDownloadUrl();
                }
            }).addOnCompleteListener(new OnCompleteListener() {
                @Override
                public void onComplete(@NonNull Task task) {
                    if (task.isSuccessful()) {
                        Uri downloadUri = task.getResult();
                        progressDialog.dismiss();
                        // Continue with the task to get the download URL
                        saveUrlToCategory(downloadUri.toString(),categoryIdSelect);
                    } else {
                        Toast.makeText(UploadWallpaper.this, "Fail UPLOAD", Toast.LENGTH_SHORT).show();
                    }
                }
            }).addOnSuccessListener(new OnSuccessListener() {
                @Override
                public void onSuccess(Uri uri) {
                    progressDialog.setMessage("Uploaded: ");
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    progressDialog.dismiss();
                    Toast.makeText(UploadWallpaper.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
    

    FOR THOSE WHO ARE USING LATEST FIREBASE VERSION taskSnapshot.getDownloadUrl() method is DEPRECATED or OBSOLETE !!

提交回复
热议问题