Grab the firebase download link and save a database string to be displayed in cardview via Picasso or similar

Asked

Viewed 408 times

1

Good evening, you guys. I’m doing a job that I need to get the download URL of the image I sent to Torage, save this URL in the database to be able to display this image in cardview using the Picasso library. I can send the image to Torage, the information to the database, but I need that link. getDownloadURL returns a URL that looks like Picasso can’t access or is not an access link. In Storage has a link that if I put it directly in the database, Picasso shows normally, I need to get this link every time I insert an image and save in the database, so just Picasso access this reference and show. This image is sent by Activityresult, then I’ll even improve it, but for now it’s working, I just need that URL same

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == GALERIA_IMAGENS) {
            Uri selectedImage = data.getData();
            String[] filePath = {MediaStore.Images.Media.DATA};
            Cursor c = getContentResolver().query(selectedImage, filePath, null, null, null);
            c.moveToFirst();
            int columnIndex = c.getColumnIndex(filePath[0]);
            String picturePath = c.getString(columnIndex);
            c.close();
            Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath));

            imagemURL = mStorageRef.getDownloadUrl().toString();
            imagePath = mStorageRef.child("imagens_livros").child(selectedImage.getLastPathSegment() + ".jpg");
            imagePath.putFile(selectedImage)
                    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                            Toast.makeText(RegistrarLivro.this, "Imagem carregada com sucesso", Toast.LENGTH_SHORT).show();
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Toast.makeText(RegistrarLivro.this, "Erro! Não conseguimos enviar a imagem. Tente novamente", Toast.LENGTH_SHORT).show();
                        }
                    });
            imagem.setImageBitmap(thumbnail);
        }

  • See if it helps you: https://stackoverflow.com/questions/38424203/firebase-storage-getting-image-url

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.