Android Firebase upload file time
<p>Hi I am implementing the storage upload in firebase for images. </p>

<p>What I am doing is select an image from my gallery, then display it on a ImageView and then upload it to the storage. </p>

<p>Everything works. But my concern is the first time I upload an image, I have tested and takes around a minute to return the download path. </p>

<p>After the first time takes less than a second. My problem is that I want to use that path for another ImageViews after closing the "upload image" activity.</p>

<p>Here is my code. </p>

<p>I have a dialog to select the gallery(I will have the facebook option later)</p>

<pre><code>    private View.OnClickListener dialogListener = new View.OnClickListener() {

    @Override
    public void onClick(View view) { clicked.length());
        final Dialog dialog = new Dialog(EditProfileActivity.this);
        dialog.setContentView(R.layout.galleryoptions);
        dialog.setTitle("Gallery Options");

        Button gallery = (Button) dialog.findViewById(R.id.buttonGallery);
        gallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
                Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, RESULT_LOAD_IMAGE);
            }
        });

        dialog.show();
    }
};
</code></pre>

<p>Then here is the Activity Result</p>

<pre><code>@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        //GET PATHS
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        Log.d(TAG, "PICTURE PATH IN PHONE: " + picturePath);
        cursor.close();
        clicked = "iv_"+clicked;
        int resID = getResources().getIdentifier(clicked, "id", "com.my.project");
        ImageView imageView = (ImageView) findViewById(resID);
        imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

        //UPLOAD FILE TO FIREBASE
        Uri file  = Uri. fromFile(new File(picturePath));
        String extension = file.getLastPathSegment();
        extension = extension.substring(extension.lastIndexOf("."));
        StorageReference riversRef = storageRef.child("images/"+ user.getUid().toString()+"/"+clicked+extension);
        UploadTask uploadTask = riversRef.putFile(file);

        // Register observers to listen for when the download is done or if it fails
        uploadTask.addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception exception) {
                // Handle unsuccessful uploads
            }
        }).addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
                Uri downloadUrl = taskSnapshot.getDownloadUrl();
                Log.d(TAG, "DOWNLOAD PATH IN FIREBASE: " + downloadUrl);
            }
        });
    }


}
</code></pre>

<p>The time between both logs "PATH IN PHONE" and "PATH IN FIREBASE" is around a minute the first time, then is quite fast. The question is, do you know a way or method or pattern to have the speed upload all the time and not just the second time?
Or what do you suggest? is it better store the image in Base64 using the realtime database instead of storage?</p>