我想问一下,我是否可以使用从 UploadTask.TaskSnapshot
获取的下载网址,并将其保存到我的Firebase实时数据库。或者我是否必须使用Firebase文档here中建议的方法?
mStorageRef = FirebaseStorage.getInstance().getReference();
mStorageRef.child("thumbnails")
.child("thumbnail")
.putFile(file)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot snapshot) {
//Successfully Got a Thumbnail URL
mThumbnailURL = snapshot.getMetadata().getDownloadUrl().toString();
//Upload link to firebase
FirebaseDatabase.getInstance.getReference()
.child("thumnail_links")
.push()
.putValue(mThumbnailURL);
}
});
mStorageRef.child("thumbnails")
.child("thumbnail")
.getDownloadLink()
.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Picasso.with(MainActivity.this)
.load(uri.toString())
.into(mMyImageView);
}
});
FirebaseDatabase.getInstance().getReference()
.child("thumbnials")
.child(pushKey).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
String url = (String) dataSnapshot.getValue();
Picasso.with(MainActivity.this)
.load(url)
.into(mMyImageView);
}
}
//...
});
我使用的方法有什么问题吗?即下载URL是否经常更改e.t.c ...?