0
I’m having trouble updating the method. getDownloadUrl( ); from firebase, I’m trying to save an image in Storege and lego after taking the url and saving it as a path in Database.
private void publicarPostagem(){
final Postagem postagem = new Postagem();
postagem.setIdUsuario(idUsuarioLogado);
postagem.setDescricao(textDescricaoFiltro.getText().toString());
//Recuperar dados da imagem para o firebase
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imagem.compress(Bitmap.CompressFormat.JPEG, 70, baos);
byte[] dadosImagem = baos.toByteArray();
//Salvar imagem no Stogere
StorageReference storageRef = ConfiguracaoFirebase.getFirebaseStorage();
StorageReference imagemRef = storageRef
.child("imagens")
.child("postagens")
.child( postagem.getId() + ".jpeg");
UploadTask uploadTask = imagemRef.putBytes( dadosImagem );
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(FiltroActivity.this,
"Erro ao salvar a imagem, tente novamente!",
Toast.LENGTH_SHORT).show();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//Recuperar local da foto
Task<Uri> url = taskSnapshot.getStorage().getDownloadUrl( );
postagem.setCaminhoFoto(url.toString());
Log.i("postagem", "url:" + postagem.getCaminhoFoto());
/*
* Tentei ressolver assim mas não consigo recuperar a url da imagem
*
*
* */
//Salvar postagem
if( postagem.salvar() ){
Toast.makeText(FiltroActivity.this,
"Sucesso ao salvar postagem!",
Toast.LENGTH_SHORT).show();
finish();
}
}
});
}
Using this code I have an error in
//Recuperar local da foto
Uri url = taskSnapshot.getDownloadUrl();
postagem.setCaminhoFoto( url.toString() );
I tried to use this method
//Recuperar local da foto
Task<Uri> url = taskSnapshot.getStorage().getDownloadUrl( );
postagem.setCaminhoFoto(url.toString());
Already using this method I can’t recover the true image url.
But I’m saving this at firebase