Package com.amazonaws.services.s3.transfer

Examples of com.amazonaws.services.s3.transfer.Upload


  }

  private static boolean upload(AmazonS3 s3, String bucketName, String destinationFile, File source)
  {
    TransferManager mgr = new TransferManager(s3);
    Upload upload = mgr.upload(bucketName, destinationFile, source);

    try {
      upload.waitForUploadResult();
    } catch (InterruptedException e) {
      return false;
    }

    return true;
View Full Code Here


        private void uploadObject()
                throws IOException
        {
            try {
                log.debug("Starting upload for host: %s, key: %s, file: %s, size: %s", host, key, tempFile, tempFile.length());
                Upload upload = transferManager.upload(host, key, tempFile);

                if (log.isDebugEnabled()) {
                    upload.addProgressListener(createProgressListener(upload));
                }

                upload.waitForCompletion();
                log.debug("Completed upload for host: %s, key: %s", host, key);
            }
            catch (AmazonClientException e) {
                throw new IOException(e);
            }
View Full Code Here

            }

            if (objectMetaData == null) {
                try {
                    // start multipart parallel upload using amazon sdk
                    Upload up = tmx.upload(new PutObjectRequest(bucket, key,
                        file));
                    // wait for upload to finish
                    if (asyncUpload) {
                        up.addProgressListener(new S3UploadProgressListener(up,
                            identifier, file, callback));
                        LOG.debug(
                            "added upload progress listener to identifier [{}]",
                            identifier);
                    } else {
                        up.waitForUploadResult();
                        LOG.debug("synchronous upload to identifier [{}] completed.", identifier);
                        if (callback != null) {
                            callback.onSuccess(new AsyncUploadResult(
                                identifier, file));
                        }
View Full Code Here

        private void uploadObject()
                throws IOException
        {
            try {
                log.debug("Starting upload for host: %s, key: %s, file: %s, size: %s", host, key, tempFile, tempFile.length());
                Upload upload = transferManager.upload(host, key, tempFile);

                if (log.isDebugEnabled()) {
                    upload.addProgressListener(createProgressListener(upload));
                }

                upload.waitForCompletion();
                log.debug("Completed upload for host: %s, key: %s", host, key);
            }
            catch (AmazonClientException e) {
                throw new IOException(e);
            }
View Full Code Here

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(format("Multipart sending file %1$s as S3 object %2$s in "
                    + "bucket %3$s", sourceFile.getName(), key, bucketName));
        }
        TransferManager tm = new TransferManager(S3Utils.acquireClient(clientOptions));
        Upload upload = tm.upload(bucketName, key, sourceFile);
        upload.waitForCompletion();
    }
View Full Code Here

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(format("Multipart sending stream as S3 object %1$s in "
                    + "bucket %2$s", key, bucketName));
        }
        TransferManager tm = new TransferManager(S3Utils.acquireClient(clientOptions));
        Upload upload = tm.upload(bucketName, key, sourceStream, null);
        upload.waitForCompletion();
    }
View Full Code Here

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Multipart sending object to S3 using PutObjectRequest");
        }      
        TransferManager tm = new TransferManager(S3Utils.acquireClient(clientOptions));
        Upload upload = tm.upload(req);
        upload.waitForCompletion();

    }
View Full Code Here

          if (((S3FileSystem)destFile.getFileSystem()).getServerSideEncryption()) {
                       md.setServerSideEncryption(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
                   }
          final InputStream instr = content.getInputStream();
          try {
            final Upload upload = getTransferManager().upload(
              destFile.getBucket().getName(), destFile.objectKey, instr, md);
            upload.waitForCompletion();
          } finally {
            instr.close();
          }
        } else {
            // nothing useful to do if no content and can't have children
View Full Code Here

                Mimetypes.getInstance().getMimetype(getName().getBaseName()));
            if (((S3FileSystem)getFileSystem()).getServerSideEncryption())
                objectMetadata.setServerSideEncryption(
                    ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            try {
                final Upload upload = getTransferManager().upload(
                    getBucket().getName(), objectKey,
                    newInputStream(outputFileChannel), objectMetadata
                );

                upload.addProgressListener(new ProgressListener() {
                    private final int REPORT_THRESHOLD = 25; // Report every 25 percents

                    private double lastValue = 0;

                    // This method is called periodically as your transfer progresses
                    public void progressChanged(ProgressEvent progressEvent) {
                        double progress = upload.getProgress().getPercentTransfered();

                        if ((progress - lastValue) > REPORT_THRESHOLD) {
                            logger.info(
                                    "File " + objectKey +
                                    " was uploaded to " + getBucket().getName() +
                                    " for " + (int) progress + "%"
                            );

                            lastValue = progress;
                        }

                        if (progressEvent.getEventCode() == COMPLETED_EVENT_CODE) {
                            logger.info("File " + objectKey + " was successfully uploaded to " + getBucket().getName());
                        }
                    }
                });
                upload.waitForCompletion();
                doDetach();
                doAttach();
            } catch (AmazonServiceException e) {
                throw new IOException(e);
            } catch (InterruptedException e) {
View Full Code Here

        request.setProgressListener(new UploadListener(credentials, bucket, key, bytesToTransfer));
        request.setMetadata(meta);

        // Schedule put object request
        getLog().info("Uploading " + key + " (" + FileUtils.byteCountToDisplaySize((int) bytesToTransfer) + ")");
        Upload upload = transfers.upload(request);
        uploads.add(upload);
        items ++;
      }
    } catch (AmazonServiceException e) {
      getLog().error("Uploading resources failed: " + e.getMessage());
    } catch (AmazonClientException e) {
      getLog().error("Uploading resources failed: " + e.getMessage());
    }

    // Wait for uploads to be finished
    String currentUpload = null;
    try {
      Thread.sleep(1000);
      getLog().info("Waiting for " + uploads.size() + " uploads to finish...");
      while (!uploads.isEmpty()) {
        Upload upload = uploads.poll();
        currentUpload = upload.getDescription().substring("Uploading to ".length());
        if (TransferState.InProgress.equals(upload.getState()))
          getLog().debug("Waiting for upload " + currentUpload + " to finish");
        upload.waitForUploadResult();
      }
    } catch (AmazonServiceException e) {
      throw new MojoExecutionException("Error while uploading " + currentUpload);
    } catch (AmazonClientException e) {
      throw new MojoExecutionException("Error while uploading " + currentUpload);
View Full Code Here

TOP

Related Classes of com.amazonaws.services.s3.transfer.Upload

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.