Skip to content

2.02.2 firebase storage put file#56

Open
ark-srivastav wants to merge 9 commits intoudacity:1.00-starting-pointfrom
ark-srivastav:2.02-firebase-storage-put-file
Open

2.02.2 firebase storage put file#56
ark-srivastav wants to merge 9 commits intoudacity:1.00-starting-pointfrom
ark-srivastav:2.02-firebase-storage-put-file

Conversation

@ark-srivastav
Copy link

@ark-srivastav ark-srivastav commented Dec 22, 2018

Implementing Updated Storage Put File and .getDownloadUrl()

        {
            Uri uri=data.getData();
            final StorageReference picref= mstorageReference.child(uri.getLastPathSegment());
            UploadTask uploadTask=picref.putFile(uri);
            Task<Uri> task=uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
                @Override
                public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
                    if(!task.isSuccessful())
                    {
                        throw task.getException();
                    }
                    return picref.getDownloadUrl();
                }
            }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                @Override
                public void onComplete(@NonNull Task<Uri> task) {
                    if(task.isSuccessful())
                    {
                        Uri downloadUri=task.getResult();
                        mdatabaseReference.push().setValue(new FriendlyMessage(null,mUsername,downloadUri.toString()));
                    }
                }
            });
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants