Map<String, Long> importMediaBatch(
      UUID jobId,
      List<DownloadableFile> downloadableFiles,
      IdempotentImportExecutor idempotentImportExecutor,
      @NotNull final String dataClass)
      throws Exception {
    final Map<String, DownloadableFile> dataIdToDownloadableFiles =
        downloadableFiles.stream()
            .collect(
                Collectors.toMap(
                    AppleMediaInterface::getDataId, downloadableFile -> downloadableFile));

    // get upload url
    final PhotosProtocol.GetUploadUrlsResponse getUploadUrlsResponse =
        getUploadUrl(
            jobId.toString(),
            dataClass,
            downloadableFiles.stream()
                .map(AppleMediaInterface::getDataId)
                .collect(Collectors.toList()));
    final List<PhotosProtocol.AuthorizeUploadResponse> successAuthorizeUploadResponseList =
        new ArrayList<>();
    for (PhotosProtocol.AuthorizeUploadResponse authorizeUploadResponse :
        getUploadUrlsResponse.getUrlResponsesList()) {
      final String dataId = authorizeUploadResponse.getDataId();
      if (authorizeUploadResponse.hasStatus()
          && authorizeUploadResponse.getStatus().getCode() == SC_OK) {
        successAuthorizeUploadResponseList.add(authorizeUploadResponse);
      } else {
        // collect errors in get upload url
        final DownloadableFile downloadableFile = dataIdToDownloadableFiles.get(dataId);
        idempotentImportExecutor.executeAndSwallowIOExceptions(
          downloadableFile.getIdempotentId(),
          downloadableFile.getName(),
          () -> {
            throw new IOException(
                    getApplePhotosImportThrowingMessage(
                            "Fail to get upload url", ImmutableMap.of(
                                    AuditKeys.errorCode, Optional.of(String.valueOf(authorizeUploadResponse.getStatus().getCode())),
                                    AuditKeys.jobId, Optional.of(jobId.toString()),
                                    AuditKeys.dataId, Optional.of(getDataId(downloadableFile)),
                                    AuditKeys.albumId, Optional.ofNullable(downloadableFile.getFolderId()))));
          });
      }
    }

    // download then upload content
    final Map<String, DownUpResult> dataIdToUploadResponse =
      uploadContent(
        dataIdToDownloadableFiles.values().stream()
          .collect(Collectors
            .toMap(
              AppleMediaInterface::getDataId,
              DownloadableItem::getFetchableUrl)),
        successAuthorizeUploadResponseList);


    // Tell DTP about errors and prep for NewMediaRequest calls for the successes
    final List<NewMediaRequest> newMediaRequestList = new ArrayList<>();
    for (AuthorizeUploadResponse authorizeUploadResponse : successAuthorizeUploadResponseList) {
      final String dataId = authorizeUploadResponse.getDataId();
      final DownloadableFile downloadableFile = dataIdToDownloadableFiles.get(dataId);
      DownUpResult result =
          checkNotNull(
              dataIdToUploadResponse.get(dataId), "somehow missing result for dataid=%s", dataId);
      // generate newMediaRequest
      if (result.isOk()) {
        String filename = getFileName(downloadableFile);
        String description = getDescription(downloadableFile);
        String mediaType = downloadableFile.getMimeType();
        String albumId = downloadableFile.getFolderId();
        Long creationDateInMillis = getUploadedTime(downloadableFile);
        boolean isFavorite = false;
        if (downloadableFile instanceof VideoModel) {
          isFavorite = ((VideoModel) downloadableFile).getFavoriteInfo().getFavorited();
        } else if (downloadableFile instanceof PhotoModel) {
          isFavorite = ((PhotoModel) downloadableFile).getFavoriteInfo().getFavorited();
        }
        newMediaRequestList.add(
            AppleMediaInterface.createNewMediaRequest(
                dataId,
                filename,
                description,
                albumId,
                mediaType,
                null,
                creationDateInMillis,
                result.successDataId(),
                    isFavorite));
      } else {
        // collect errors in upload content
        idempotentImportExecutor.executeAndSwallowIOExceptions(
            downloadableFile.getIdempotentId(),
            downloadableFile.getName(),
            () -> {
              throw new IOException(
                  getApplePhotosImportThrowingMessage(
                      "Fail to upload content",
                      ImmutableMap.of(
                          AuditKeys.jobId, Optional.of(jobId.toString()),
                          AuditKeys.dataId, Optional.of(getDataId(downloadableFile)),
                          AuditKeys.albumId, Optional.ofNullable(downloadableFile.getFolderId()))),
                  result.error());
            });
      }
    }

    final PhotosProtocol.CreateMediaResponse createMediaResponse =
        createMedia(jobId.toString(), dataClass, newMediaRequestList);

    // collect results in create media
    long totalBytes = 0L;
    long mediaCount = 0;
    for (PhotosProtocol.NewMediaResponse newMediaResponse :
        createMediaResponse.getNewMediaResponsesList()) {
      final String dataId = newMediaResponse.getDataId();
      final DownloadableFile downloadableFile = dataIdToDownloadableFiles.get(dataId);
      if (newMediaResponse.hasStatus()
          && newMediaResponse.getStatus().getCode() == SC_OK) {
        mediaCount += 1;
        totalBytes += newMediaResponse.getFilesize();
        idempotentImportExecutor.executeAndSwallowIOExceptions(
          downloadableFile.getIdempotentId(),
          downloadableFile.getName(),
          () -> {
            monitor.debug(
              () -> "Apple importing photo",
              AuditKeys.jobId, jobId,
              AuditKeys.dataId, getDataId(downloadableFile),
              AuditKeys.albumId, downloadableFile.getFolderId(),
              AuditKeys.recordId, newMediaResponse.getRecordId());
            return newMediaResponse.getRecordId();
          });
      } else if (newMediaResponse.getStatus().getCode() == SC_CONFLICT) {
        idempotentImportExecutor.executeAndSwallowIOExceptions(
          downloadableFile.getIdempotentId(),
          downloadableFile.getName(),
          () -> {
            monitor.debug(
              () -> "duplicated photo",
              AuditKeys.jobId, jobId,
              AuditKeys.dataId, getDataId(downloadableFile),
              AuditKeys.albumId, downloadableFile.getFolderId(),
              AuditKeys.recordId, newMediaResponse.getRecordId());
            return newMediaResponse.getRecordId();
          });
      } else {
        idempotentImportExecutor.executeAndSwallowIOExceptions(
          downloadableFile.getIdempotentId(),
          downloadableFile.getName(),
          () -> {
            throw new IOException(
                    getApplePhotosImportThrowingMessage(
                "Fail to create media", ImmutableMap.of(
                            AuditKeys.errorCode, Optional.of(String.valueOf(newMediaResponse.getStatus().getCode())),
                            AuditKeys.jobId, Optional.of(jobId.toString()),
                            AuditKeys.dataId, Optional.of(getDataId(downloadableFile)),
                            AuditKeys.albumId, Optional.ofNullable(downloadableFile.getFolderId()))));
          });
      }
    }

    // return count and bytes
    monitor.info(
        () -> "Apple imported photo batch",
        AuditKeys.jobId, jobId,
        AuditKeys.totalFilesCount, mediaCount,
        AuditKeys.bytesExported, totalBytes);

    final Map<String, Long> batchImportResults =
        new ImmutableMap.Builder<String, Long>()
            .put(ApplePhotosConstants.BYTES_KEY, totalBytes)
            .put(ApplePhotosConstants.COUNT_KEY, mediaCount)
            .build();
    return batchImportResults;
  }
An interface that is synonymous to HTTP client to interact with the Apple Photos APIs.
extensions/data-transfer/portability-data-transfer-apple/src/main/java/org/datatransferproject/datatransfer/apple/photos/AppleMediaInterface.java