本文介绍了我在android firebase中使用什么而不是.getdownloadurl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
随着更新,.getDownloadUrl不再起作用,所以我想知道如何在我的代码中专门更改它
With the update, .getDownloadUrl doesn't work anymore so I was wondering how I can change it in my code specifically
<pre><pre> <pre> private void executeUploadTask(){
Toast.makeText(getActivity(), "Uploading Image", Toast.LENGTH_SHORT).show();
final String postId = FirebaseDatabase.getInstance().getReference().push().getKey();
final StorageReference storageReference = FirebaseStorage.getInstance().getReference()
.child("uploads/users" + FirebaseAuth.getInstance().getCurrentUser()
.getUid()+"/" + postId + "/upload_image");
UploadTask uploadTask = storageReference.putBytes(mUploadBytes);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getActivity(), "Filed", Toast.LENGTH_SHORT).show();
Uri firebaseUri = taskSnapshot.getDownloadUrl();
Log.d(TAG, "onSuccess: firebase download url: " + firebaseUri.toString());
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
//things that should be in the database
Post post = new Post();
post.setImage(firebaseUri.toString());
post.setDate(mDateOfUse.getText().toString());
post.setFileName(mFileName.getText().toString());
post.setGrade(mGrade.getText().toString());
post.setNameOfClass(mClass.getText().toString());
post.setPageNumber(mPage.getText().toString());
post.setReflection(mReflection.getText().toString());
post.setPost_id(postId);
post.setUser_id(FirebaseAuth.getInstance().getCurrentUser().getUid());
post.setRatingBar(Float.toString(mRatingBar.getRating()));
reference.child(getString(R.string.node_post))
.child(postId)
.setValue(post);
resetFields();
}
}
}
我尝试过的事情:
我试图实施
}
}
What I have tried:
I tried to implement
<pre lang="java">Task<Uri> urlTask = storageReference.getDownloadUrl().urlTask.addOnSuccessListener(new OnSuccessListener<>())
但我不知道将它放在我的代码中的哪个位置。请帮助我,我真的很绝望。
but I don't know where to put it in my code. Please help me, I am really desperate.
推荐答案
Uri firebaseUri = taskSnapshot.getDownloadUrl();
to
to
Task<Uri> firebaseUri = taskSnapshot.getStorage().getDownloadUrl();
<pre> final StorageReference ref = mStorageRef.child("folder_name").child(imageUri.getLastPathSegment());
//uploadTask = ref.putFile(filepa);
Task<Uri> urlTask = ref.putFile(imageUri).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();
}
// Continue with the task to get the download URL
return ref.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
Uri downloadUrl = task.getResult();
mProgress.dismiss();
} else {
// Handle failures
// ...
}
}
});
对我有用
it work for me
这篇关于我在android firebase中使用什么而不是.getdownloadurl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!