private void beginUpload(PictureFile pictureFile) {
    String full_path_on_device = pictureFile.getFull_path_on_device();
    Log.w(LOG_TAG, "try start upload file = " + full_path_on_device);
    File fileFromPath = new File(full_path_on_device);
    boolean exists = fileFromPath.exists();
    if (exists) {
      boolean addressExist = isAddressExist(pictureFile);
      Log.w(
          LOG_TAG,
          "file "
              + full_path_on_device
              + " EXIST. Try upload it. Address  exist = "
              + addressExist);

      if (!addressExist) {
        Log.w(LOG_TAG, "file " + full_path_on_device + " don't have geoname, try found it ");
        try {
          String newGeoname = retrieveGeoName(pictureFile);

          if (newGeoname != null && !newGeoname.isEmpty()) {
            renameFile(fileFromPath, pictureFile, newGeoname);
          }

        } catch (IOException e) {
          e.printStackTrace();
        }
        addressExist = isAddressExist(pictureFile);
        full_path_on_device = pictureFile.getFull_path_on_device();
        Log.w(LOG_TAG, "file " + full_path_on_device + " address retrieved  = " + addressExist);
      }

      if (addressExist) {
        File localFile = new File(full_path_on_device);
        String remoteName = pictureFile.getFilename();
        initUpload(pictureFile, localFile, remoteName);
        Log.w(LOG_TAG, "file " + full_path_on_device + " is READY. START UPLOAD AWS id");
      } else {
        Log.e(LOG_TAG, "file " + full_path_on_device + " don't receive geoname, skip it ");
        String filename = pictureFile.getFilename();
        addInFailed(filename);

        uploadCycleFinished();
      }

    } else {
      Log.e(LOG_TAG, "file " + full_path_on_device + " NOT EXIST. Remove it from database");
      PictureFile deletedFile = daoHelper.getFileFromPath(full_path_on_device);
      if (deletedFile != null) {
        daoHelper.pictureFileDao.delete(deletedFile);
        daoHelper.onPictureFilesUpdated();
      }
      Intent intent = new Intent(BroadcastReceiverHelper.ACTION);
      intent.putExtra(BroadcastReceiverHelper.PARAM, BroadcastReceiverHelper.PARAM_DELETED);
      String name = fileFromPath.getName();
      intent.putExtra(BroadcastReceiverHelper.FILENAME, name);
      sendBroadcast(intent);

      uploadCycleFinished();
    }
  }
  private void renameFile(File oldFile, PictureFile pictureFile, String newGeoname) {

    pictureFile.setGeo_name(newGeoname);

    Double lat = pictureFile.getLat();
    Double lon = pictureFile.getLon();
    String geoname = newGeoname;
    Long time = pictureFile.getTime();

    String oldPath = pictureFile.getFull_path_on_device();
    int indexForSlash = oldPath.lastIndexOf("/");
    String parentPath = oldPath.substring(0, indexForSlash + 1);
    String timestamp = StorageHelper.formatTimeForFilename(time);
    String location = StorageHelper.formatLatLonGeoname(lat, lon, geoname);
    String username = daoHelper.getUserName();
    String newName = StorageHelper.formatFilename(username, location, timestamp);
    String newPath = parentPath + newName;

    pictureFile.setFilename(newName);
    pictureFile.setFull_path_on_device(newPath);

    File newFile = new File(newPath);
    oldFile.renameTo(newFile);

    Log.w(LOG_TAG, "Renamed " + oldPath + " to " + newPath);

    daoHelper.pictureFileDao.update(pictureFile);
    daoHelper.onPictureFilesUpdated();
  }