我必须将某些信息上传到实时数据库中。除图片网址外,所有详细信息均已正确上传到其中。使用taskSnapshot.getMetadata()。getReference()。getDownloadUrl()我得到了类似com.google.android.gms.tasks.zzu@441922b的图像链接。该文件已上载到存储中。但是我没有确切的下载网址来访问它。代码在下面添加
TipsAdminActivityUpload.java
private void uploadFile() {
if (mImageUri != null) {
StorageReference fileReference = mStorageRef.child(System.currentTimeMillis()
+ "." + getFileExtension(mImageUri));
uploadProgressBar.setVisibility(View.VISIBLE);
uploadProgressBar.setIndeterminate(true);
mUploadTask = fileReference.putFile(mImageUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot> () {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
uploadProgressBar.setVisibility(View.VISIBLE);
uploadProgressBar.setIndeterminate(false);
uploadProgressBar.setProgress(0);
}
}, 500);
Toast.makeText(TipsAdminActivityUpload.this, "Proses Upload Telah Selesai", Toast.LENGTH_LONG).show();
Tips upload = new Tips(judulEditText.getText().toString().trim(),
taskSnapshot.getMetadata().getReference().getDownloadUrl().toString(),
descriptionEditText.getText().toString());
String uploadId = mDatabaseRef.push().getKey();
mDatabaseRef.child(uploadId).setValue(upload);
uploadProgressBar.setVisibility(View.INVISIBLE);
openImagesActivity ();
}
})
.addOnFailureListener(new OnFailureListener () {
@Override
public void onFailure(Exception e) {
uploadProgressBar.setVisibility(View.INVISIBLE);
Toast.makeText(TipsAdminActivityUpload.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot> () {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount());
uploadProgressBar.setProgress((int) progress);
}
});
} else {
Toast.makeText(this, "Tidak ada Item yang kami pilih", Toast.LENGTH_SHORT).show();
}
}