private UploadFileRequest createRequest()

in teamcity-s3-sdk/src/main/java/jetbrains/buildServer/artifacts/s3/publish/S3RegularFileUploader.java [94:132]


  private UploadFileRequest createRequest(@NotNull final String pathPrefix,
                                      @NotNull final String bucketName,
                                      @NotNull final Consumer<FileUploadInfo> uploadConsumer,
                                      @NotNull final Pair<String, File> fileWithPath) {
    final File file = fileWithPath.getSecond();
    if (!file.exists()) {
      myLogger.warn("Artifact \"" + file.getAbsolutePath() + "\" does not exist and will not be published to the server");
      return null;
    }
    final String artifactPath = S3Util.normalizeArtifactPath(fileWithPath.getFirst(), file);
    final String objectKey = pathPrefix + artifactPath;

    uploadConsumer.accept(new FileUploadInfo(artifactPath, file.getAbsolutePath(), file.length(), null));

    TransferListener loggingTransferListener = new TransferListener() {
      final AtomicLong fileSize = new AtomicLong(file.length());
      final AtomicInteger reportCounter = new AtomicInteger(0);

      @Override
      public void bytesTransferred(Context.BytesTransferred context) {
        final int percentage = 100 - (int)Math.round((fileSize.getAndAdd(-context.progressSnapshot().transferredBytes()) * 100.) / file.length());
        if (percentage >= reportCounter.get() + 10) {
          myLogger.debug("S3 Multipart Uploading [" + file.getName() + "] " + percentage + "%");
          reportCounter.set(percentage);
        }
      }
    };

    return UploadFileRequest.builder()
                            .putObjectRequest(b -> b
                              .bucket(bucketName)
                              .key(objectKey)
                              .contentType(S3Util.getContentType(file))
                              .acl(myS3Configuration.getAcl())
                            )
                            .addTransferListener(loggingTransferListener)
                            .source(file)
                            .build();
  }