How to get URL from Firebase Storage getDownloadURL

后端 未结 10 2020
小蘑菇
小蘑菇 2020-11-21 04:54

I\'m trying to get the \"long term persistent download link\" to files in our Firebase storage bucket. I\'ve changed the permissions of this to

service fireb         


        
10条回答
  •  被撕碎了的回忆
    2020-11-21 05:53

    StorageReference mStorageRef = FirebaseStorage.getInstance().getReference();
    
    final   StorageReference fileupload=mStorageRef.child("Photos").child(fileUri.getLastPathSegment());
    UploadTask uploadTask = fileupload.putFile(fileUri);
    
    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();
                    Picasso.get().load(downloadUri.toString()).into(image);
    
                } else {
                     // Handle failures
                }
           }
    });
    

提交回复
热议问题