title: Upload image to firebase storage
body: <p>I'm trying to upload an image taken from the camera to the firebase storage, an message dialog appears but it keeps on charging and no images are uploaded to the storage.
  Also I'd like to know, how can I get back the image sent from a specific user? should I give the image the user name to the image so I can get it back with his name?</p>
  
  <pre><code>public class ProfileActivity extends AppCompatActivity {
      public static final int CAMERA_REQUEST = 10;
      private LocationService service;
      private Button uploadbtn;
      private ImageView imgSpecimentPhoto;
      private ImageView imgSpecimentPhoto2;
      private ImageView imgSpecimentPhoto3;
      private StorageReference storage;
      private ProgressDialog mProgress;
      Uri photoURI;
      String mCurrentPhotoPath;
      private File createImageFile() throws IOException{
          //Create an image file name
          String timeStamp = new SimpleDateFormat( "yyyyMMdd_HHmmss" ).format( new Date());
          String imageFileName = "JPEG_" + timeStamp + "_.";
          File storageDir = getExternalFilesDir( Environment.DIRECTORY_PICTURES );
          File image = File.createTempFile(
                  imageFileName,
                  ".jpg",
                  storageDir
          );
          mCurrentPhotoPath = image.getAbsolutePath();
          return image;
      }
      private void dispatchTakePictureIntent(){
          Intent takePictureIntent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
          if(takePictureIntent.resolveActivity( getPackageManager())!= null){
              //Create the file where the photo should go
              File photoFile = null;
              try{
                  photoFile = createImageFile();
              }catch (IOException ex){
                  System.out.println("error taking the pic");
              }
              //Continue only if the file was successfull
              if(photoFile != null){
                  photoURI = FileProvider.getUriForFile( this, "com.example.android.fileprovider",photoFile);
                  takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                  startActivityForResult( takePictureIntent, CAMERA_REQUEST );
              }
          }
      }
  
  
      private View currentView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_profile );
          service = new LocationService(this);
          uploadbtn = (Button) findViewById(R.id.upload);
          storage = FirebaseStorage.getInstance().getReference();
          mProgress = new ProgressDialog( this );
  
          //get access to the image view
          imgSpecimentPhoto = findViewById(R.id.camerabtn);
          imgSpecimentPhoto2 = findViewById(R.id.camerabtn5 );
          imgSpecimentPhoto3 = findViewById(R.id.camerabtn6);
  
  
          uploadbtn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  mProgress.setMessage("Uploading...");
                  mProgress.show();
                  dispatchTakePictureIntent();
  
  
                      }
                  } );
  
  
  
              }
  
  
      public void checkPermission() {
          if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
                  ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
                  ) {//Can add more as per requirement
  
              ActivityCompat.requestPermissions(this,
                      new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION},
                      123);
          }
      }
  
      public void btnTakePhotoClicked(View v) {
          Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          startActivityForResult(cameraIntent, CAMERA_REQUEST);
          System.out.println("first");
          currentView= v;
  
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          photoURI = data.getData();
  
  
          //did the user chose okay
          if(requestCode == CAMERA_REQUEST &amp;&amp; resultCode == RESULT_OK){
  
              //we are hearing back grom the camera
              Bitmap cameraImage = (Bitmap) data.getExtras().get( "data" );
              //now we have the image
              ImageView cur = (ImageView) currentView;
              cur.setImageBitmap( cameraImage );
              if (cur.getId() == imgSpecimentPhoto.getId()) {
                  imgSpecimentPhoto2.setVisibility( View.VISIBLE );
              }
              if (cur.getId() == imgSpecimentPhoto2.getId()) {
                  imgSpecimentPhoto3.setVisibility( View.VISIBLE );
  
              StorageReference filepath = storage.child("Photos").child( photoURI.getLastPathSegment());
              filepath.putFile( photoURI).addOnSuccessListener( new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
                  @Override
                  public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                      Toast.makeText(ProfileActivity.this, "Upload Successfull", Toast.LENGTH_SHORT).show();
                      mProgress.dismiss();
  
                  }
              } ).addOnFailureListener( new OnFailureListener() {
                  @Override
                  public void onFailure(@NonNull Exception e) {
                      Toast.makeText( ProfileActivity.this, "Upload Failed", Toast.LENGTH_SHORT).show();
                  }
              } );
  
  
  
                                  }
  
              }
  
  
          }}
  </code></pre>