public Optional<StoredImage> tryLoadImage(ImageRef ref) {
    Optional<StoredReport> report = reportStore.tryLoadReport(ref.getOwnerId(), ref.getReportId());
    Preconditions.checkArgument(report.isPresent(), "Report not found: " + ref.toString());

    return Optional.fromNullable(
        backend()
            .load()
            .type(StoredImage.class)
            .parent(report.get())
            .id(StoredImage.toKey(ref))
            .now());
  }
  private void addImage(ImageRef ref, String imageCsObjectName, BlobKey blobKey) {
    Optional<StoredReport> report = reportStore.tryLoadReport(ref.getOwnerId(), ref.getReportId());
    Preconditions.checkArgument(report.isPresent(), "Report not found: " + ref.toString());

    StoredImage image =
        StoredImage.builder()
            .setKey(StoredImage.toKey(ref))
            .setReport(Ref.create(report.get()))
            .setImageFileName(ref.getImageName())
            .setCloudStorageObjectName(imageCsObjectName)
            .setBlobKey(blobKey.getKeyString())
            .build();
    backend().save().entity(image).now();
  }
  private static BlobKey getBlobkKey(ImageRef ref) {
    ImageStore store = new ImageStore();
    store.init();

    Optional<StoredImage> image = store.tryLoadImage(ref);
    if (image.isPresent()) {
      log.info("Using blobkey: " + image.get().getBlobKey());
      return new BlobKey(image.get().getBlobKey());
    } else {
      GcsFilename oldGcsFileName = createOldGcsFileName(ref.getReportId(), ref.getImageName());
      log.info("Using old GCS fileName: " + oldGcsFileName.toString());

      BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
      // Does not work on dev server.
      return blobstoreService.createGsBlobKey(
          "/gs/" + oldGcsFileName.getBucketName() + "/" + oldGcsFileName.getObjectName());
    }
  }
 public static String getUploadUrl(ImageRef ref) {
   BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
   return blobstoreService.createUploadUrl(
       "/backend/image-post-upload?ref=" + BaseEncoding.base64().encode(ref.toByteArray()),
       UploadOptions.Builder.withGoogleStorageBucketName(getBucket()));
 }