private void uploadImage() {
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Загрузка...");
progressDialog.show();
final StorageReference ref = storageReference.child(avatarUrl);
ref.putFile(Uri.parse(Settings.uriImage))
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
Toast.makeText(Settings.this, "Фото профиля подключено", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(Settings.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());
progressDialog.setMessage("Прогресс " + (int) progress + "%");
}
});
avatarUrlFinal = avatarUrl;
}
private void gettingImage () {
StorageReference islandRef = storageReference.child(avatarUrlFinal);
Uri test = islandRef.getDownloadUrl().getResult();
现在islandRef.getDownloadUrl()。getResult()返回图像的私有链接(例如gs://xxx.appspot.com/images/xxx
),而不是公开链接(对于例如https://firebasestorage.googleapis.com/v0/b/xxx.appspot.com/o/images%xxx
)。
如何获取下载的图像的公共链接?
答案 0 :(得分:1)
正确的密码
StorageReference islandRef = storageReference.child(avatarUrlFinal);
islandRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
String test = uri.toString();
Toast.makeText(Settings.this, test, Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Settings.this, "Ошибка", Toast.LENGTH_SHORT).show();
}
});