title: Upload Images to Firebase Storage and have a link in Firebase Database
body: <p>I am currently working on an Incident Reporting application which allows users to choose and upload images.</p>
  
  <p>I am already successful in posting images to Firebase Storage but I am wondering if it is possible to have a link/url in Firebase Database from which I can click to redirect me to Firebase Storage to see that image.</p>
  
  <p>I want this function so that along with user inputs such as Title, Date, Remarks, the end-user would be able to see the "image" child with the link along with other inputs</p>
  
  <p>I have tried searching StackOverflow and Youtube for answers but most of them are old and seem outdated. There is a command "getDownloadUrl" but i believe it has been deprecated. </p>
  
  <p>This is the code from my class that uploads my image to Firebase Storage </p>
  
  <pre><code>  private void uploadImage() {
  
      if (filePath != null) {
  
          final ProgressDialog progressDialog = new ProgressDialog(getActivity());
          progressDialog.setTitle("Uploading...");
          progressDialog.show();
  
          StorageReference ref = storageReference.child("images/"+ UUID.randomUUID().toString());
          ref.putFile(filePath)
                  .addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
                      @Override
                      public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                          progressDialog.dismiss();
                          Toast.makeText(getActivity(),"Uploaded", Toast.LENGTH_SHORT).show();
                      }
                  })
                  .addOnFailureListener(new OnFailureListener() {
                      @Override
                      public void onFailure(@NonNull Exception e) {
                          progressDialog.dismiss();
                          Toast.makeText(getActivity(),"Failed"+e.getMessage(), Toast.LENGTH_SHORT).show();
                      }
                  })
                  .addOnProgressListener(new OnProgressListener&lt;UploadTask.TaskSnapshot&gt;() {
                      @Override
                      public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                          double progress = (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot.getTotalByteCount());
                          progressDialog.setMessage("Uploaded"+(int)progress+"%");
                      }
                  });
      }
  }
  
  private void chooseImage() {
      Intent intent = new Intent();
      intent.setType("image/*");
      intent.setAction(Intent.ACTION_GET_CONTENT);
      startActivityForResult(Intent.createChooser(intent,"Select Picture"),PICK_IMAGE_REQUEST);
  }
  </code></pre>
  
  <p>ReportFragment</p>
  
  <pre><code>import static android.app.Activity.RESULT_OK;
  import static com.firebase.ui.auth.AuthUI.getApplicationContext;
  
  public class ReportFragment extends Fragment implements 
  AdapterView.OnItemSelectedListener{
  
  private Button btnChoose,btnUpload;
  private ImageView imageView;
  private Uri filePath;
  private final int PICK_IMAGE_REQUEST = 71;
  private TextView mDisplayDate;
  private DatePickerDialog.OnDateSetListener mDateSetListener;
  
  private EditText reportedBy;
  private TextView date; //upstairs declare alr as mDisplayDate
  private Spinner spinner; //downstairs declare alr as spinner3
  private EditText location;
  private Spinner spinner2; //downstairs declare alr as spinner2
  private EditText details;
  private Spinner spinner3; //downstairs declare alr as spinner1
  private EditText remarks;
  private EditText title;
  private Button submitIncident;
  
  
  public static TextView resultTextView3;
  Button scan_btn3;
  
  private ImageView imageView2;
  private TextView imgUrl1;
  
  DatabaseReference databaseIncidents;
  FirebaseStorage storage;
  StorageReference storageReference;
  
  @Nullable
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable 
  ViewGroup container, @Nullable Bundle savedInstanceState) {
      View v = inflater.inflate(R.layout.fragment_report, container, false);
  
      databaseIncidents = 
  FirebaseDatabase.getInstance().getReference("Incidents");
      storage = FirebaseStorage.getInstance();
      storageReference = storage.getReference();
  
      btnChoose = (Button) v.findViewById(R.id.btnChoose);
      btnUpload = (Button) v.findViewById(R.id.btnUpload);
      imageView = (ImageView) v.findViewById(R.id.imgView);
  
      reportedBy = (EditText) v.findViewById(R.id.etreportedby);
  //        Below have already line 151
  //        date = (TextView) v.findViewById(R.id.tvdate);
      location = (EditText) v.findViewById(R.id.etlocation);
      details = (EditText) v.findViewById(R.id.etdetails);
      remarks = (EditText) v.findViewById(R.id.etremarks);
      title = (EditText) v.findViewById(R.id.ettitle);
      submitIncident = (Button) v.findViewById(R.id.btnSubmit);
  
  
      resultTextView3 = (TextView)v.findViewById(R.id.result_text3);
      scan_btn3 = (Button)v.findViewById(R.id.btn_scan3);
  
      imageView2 = (ImageView)v.findViewById(R.id.ivimagescardinput);
      imgUrl1 = (TextView)v.findViewById(R.id.tvimagescard);
  
  
  
  
  
  
      btnChoose.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              chooseImage();
          }
      });
  //        btnUpload.setOnClickListener(new View.OnClickListener() {
  //            @Override
  //            public void onClick(View v) {
  //                uploadImage();
  //            }
  //        });
  
  
      scan_btn3.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              startActivity(new 
  Intent(getActivity(),ScanCodeActivity.class));
  
          }
      });
  
      submitIncident.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              incidentSubmit();
              uploadImage();
  
              Glide.with(getActivity()).load(URL).into(imageView2);
          }
      });
  
      return`
  
  
  }
  
  private void incidentSubmit(){
      String reportedname = reportedBy.getText().toString().trim();
      String location1 = location.getText().toString();
      String details1 = details.getText().toString();
      String remarks1 = remarks.getText().toString();
      String urgency1 = spinner.getSelectedItem().toString();
      String type1 = spinner2.getSelectedItem().toString();
      String splocation1 = spinner3.getSelectedItem().toString();
      String date1 = mDisplayDate.getText().toString();
      String title1 = title.getText().toString();
      String qrlocation1 = resultTextView3.getText().toString();
      String image1 = imgUrl1.getText().toString();
  
  
      if(!TextUtils.isEmpty(reportedname)) {
  
          String incidentId = databaseIncidents.push().getKey();
          Incident incident = new 
  
  
  
  Incident(reportedname,location1,details1,remarks1,urgency1,type1,splocation1,date1,title1,qrlocation1,image1);
              databaseIncidents.child(incidentId).setValue(incident);
  
              Toast.makeText(getActivity(), "Incident Added", Toast.LENGTH_LONG).show();
              FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
              fragmentTransaction.replace(R.id.fragment_container, new IncmanFragment());
              fragmentTransaction.commit();
              } else {
              Toast.makeText(getActivity(), "All fields must be entered",Toast.LENGTH_LONG).show();
          }
      }
  private void uploadImage() {
  
  
      if (filePath != null) {
  
          final StorageReference ref = storageReference.child("images/"+ UUID.randomUUID().toString());
  
         ref.putFile(filePath).addOnCompleteListener(new OnCompleteListener&lt;UploadTask.TaskSnapshot&gt;() {
             @Override
             public void onComplete(@NonNull Task&lt;UploadTask.TaskSnapshot&gt; task) {
                 if(task.isSuccessful()) {
                     ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener&lt;Uri&gt;() {
                         @Override
                         public void onSuccess(Uri uri) {
                             String URL = uri.toString();
                             databaseIncidents.child("imageId").setValue(URL.toString());
  
                         }
  
                     });
  
                 }
  
             }
  
         });
  
      }
  
  
  }
  
  
  private void chooseImage() {
      Intent intent = new Intent();
      intent.setType("image/*");
      intent.setAction(Intent.ACTION_GET_CONTENT);
      startActivityForResult(Intent.createChooser(intent,"Select Picture"),PICK_IMAGE_REQUEST);
  }
  
  
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if(requestCode == PICK_IMAGE_REQUEST &amp;&amp; resultCode == RESULT_OK
              &amp;&amp; data != null &amp;&amp; data.getData() != null) {
          filePath = data.getData();
          try{
              Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getApplicationContext().getContentResolver(),filePath);
              imageView.setImageBitmap(bitmap);
          }
          catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  @Override
  public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
      String text = parent.getItemAtPosition(position).toString();
      Toast.makeText(parent.getContext(), text, Toast.LENGTH_SHORT).show();
  }
  
  @Override
  public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
  }
  }
  </code></pre>
  
  <p>Any help or tutorials is greatly appreciated!</p>
  
  <p><a href="https://i.stack.imgur.com/WafEh.png" rel="nofollow noreferrer">Database Inputs (not including image)</a></p>