当前位置: 首页>>代码示例>>Java>>正文


Java TransferManager.upload方法代码示例

本文整理汇总了Java中com.amazonaws.services.s3.transfer.TransferManager.upload方法的典型用法代码示例。如果您正苦于以下问题:Java TransferManager.upload方法的具体用法?Java TransferManager.upload怎么用?Java TransferManager.upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.s3.transfer.TransferManager的用法示例。


在下文中一共展示了TransferManager.upload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadToS3

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
private String uploadToS3(String bucket, String key, MultipartFile file) {
    final AmazonS3 s3 = s3ClientFactory.createClient();
    final TransferManager transferManager = TransferManagerBuilder.standard().withS3Client(s3).build();
    try {
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(file.getSize());
        metadata.setContentType(file.getContentType());

        byte[] resultByte = DigestUtils.md5(file.getBytes());
        String streamMD5 = new String(Base64.encodeBase64(resultByte));
        metadata.setContentMD5(streamMD5);

        Upload upload = transferManager.upload(bucket, key, file.getInputStream(), metadata);
        upload.waitForCompletion();
        return streamMD5;
    } catch (AmazonServiceException | InterruptedException | IOException e) {
        logger.error("Error uploading file: {}", e.toString());
        return null;
    } finally {
        transferManager.shutdownNow();
    }
}
 
开发者ID:grassrootza,项目名称:grassroot-platform,代码行数:23,代码来源:StorageBrokerImpl.java

示例2: shouldUploadInParallel

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
/**
 * Tests if an object can be uploaded asynchronously
 *
 * @throws Exception not expected
 */
@Test
public void shouldUploadInParallel() throws Exception {
  final File uploadFile = new File(UPLOAD_FILE_NAME);

  s3Client.createBucket(BUCKET_NAME);

  final TransferManager transferManager = createDefaultTransferManager();
  final Upload upload =
      transferManager.upload(new PutObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME, uploadFile));
  final UploadResult uploadResult = upload.waitForUploadResult();

  assertThat(uploadResult.getKey(), equalTo(UPLOAD_FILE_NAME));

  final S3Object getResult = s3Client.getObject(BUCKET_NAME, UPLOAD_FILE_NAME);
  assertThat(getResult.getKey(), equalTo(UPLOAD_FILE_NAME));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:22,代码来源:AmazonClientUploadIT.java

示例3: checkRangeDownloads

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
/**
 * Verify that range-downloads work.
 *
 * @throws Exception not expected
 */
@Test
public void checkRangeDownloads() throws Exception {
  final File uploadFile = new File(UPLOAD_FILE_NAME);

  s3Client.createBucket(BUCKET_NAME);

  final TransferManager transferManager = createDefaultTransferManager();
  final Upload upload =
      transferManager.upload(new PutObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME, uploadFile));
  upload.waitForUploadResult();

  final File downloadFile = File.createTempFile(UUID.randomUUID().toString(), null);
  transferManager
      .download(new GetObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME).withRange(1, 2),
          downloadFile)
      .waitForCompletion();
  assertThat("Invalid file length", downloadFile.length(), is(2L));

  transferManager
      .download(new GetObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME).withRange(0, 1000),
          downloadFile)
      .waitForCompletion();
  assertThat("Invalid file length", downloadFile.length(), is(uploadFile.length()));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:30,代码来源:AmazonClientUploadIT.java

示例4: uploadArtifactStream

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
private void uploadArtifactStream(IndexArtifact ia, StorageRequest sr) throws LocalStorageException
{
    try
    {
        TransferManager tx = new TransferManager(client);
        ObjectMetadata om = new ObjectMetadata();
        om.setContentLength(sr.getLength());

        String key = getPath() + ia.getLocation() + "/" + sr.getFilename();
        
        Upload myUpload = tx.upload(bucketName, key, sr.getNewStream(), om);
        myUpload.waitForCompletion();
    }
    catch (Exception exc)
    {
        logger.error(exc.getLocalizedMessage());
        throw new LocalStorageException(exc);
    }
}
 
开发者ID:Spedge,项目名称:hangar,代码行数:20,代码来源:S3Storage.java

示例5: uploadDirectoryOrFile

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
@Override
public Transfer uploadDirectoryOrFile(final String bucketName, final File source,
		final String virtualDirectoryKeyPrefix) throws AmazonClientException, AmazonServiceException, IOException {
	LOGGER.info("uploadDirectoryOrFile invoked, bucketName: {} , Source: {}", bucketName,
			source.getAbsolutePath());
	Transfer transfer = null;
	final TransferManager trMgr = new TransferManager(s3client);
	if (source.isFile()) {
		transfer = trMgr.upload(bucketName,source.getPath(),source);
	} else if (source.isDirectory()) {
		//Upload recursively
		//virtualDirectoryKeyPrefix could be virtual directory name inside the bucket
		transfer = trMgr.uploadDirectory(bucketName, virtualDirectoryKeyPrefix, source, true);
	} else {
		throw new FileNotFoundException("Source is neither a regular file nor a directory " + source);
	}
	return transfer;
}
 
开发者ID:abhinavmishra14,项目名称:aws-s3-utils,代码行数:19,代码来源:AwsS3IamServiceImpl.java

示例6: call

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
@Override
public Integer call() throws Exception {
    TransferManager t = new TransferManager(amazonS3Client);

    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setUserMetadata(metadata);
    if(sse) {
        objectMetadata.setSSEAlgorithm(SSEAlgorithm.AES256.getAlgorithm());
    }

    Upload u = t.upload(new PutObjectRequest(bucket, key, inputFile).withMetadata(objectMetadata));

    // TODO this listener spews out garbage >100% on a retry, add a test to verify
    if (progressListener != null) {
        progressListener.withTransferProgress(new TransferProgressWrapper(u.getProgress()));
        u.addProgressListener(progressListener);
    }
    try {
        u.waitForCompletion();
    } finally {
        t.shutdownNow();
    }
    return 0;
}
 
开发者ID:rholder,项目名称:esthree,代码行数:25,代码来源:Put.java

示例7: shouldUploadAndDownloadStream

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
/**
 * Stores a file in a previously created bucket. Downloads the file again and compares checksums
 *
 * @throws Exception if FileStreams can not be read
 */
@Test
public void shouldUploadAndDownloadStream() throws Exception {
  s3Client.createBucket(BUCKET_NAME);
  final String resourceId = UUID.randomUUID().toString();

  final byte[] resource = new byte[] {1, 2, 3, 4, 5};
  final ByteArrayInputStream bais = new ByteArrayInputStream(resource);

  final ObjectMetadata objectMetadata = new ObjectMetadata();
  objectMetadata.setContentLength(resource.length);
  final PutObjectRequest putObjectRequest =
      new PutObjectRequest(BUCKET_NAME, resourceId, bais, objectMetadata);

  final TransferManager tm = createDefaultTransferManager();
  final Upload upload = tm.upload(putObjectRequest);

  upload.waitForUploadResult();

  final S3Object s3Object = s3Client.getObject(BUCKET_NAME, resourceId);

  final String uploadHash = HashUtil.getDigest(new ByteArrayInputStream(resource));
  final String downloadedHash = HashUtil.getDigest(s3Object.getObjectContent());
  s3Object.close();

  assertThat("Up- and downloaded Files should have equal Hashes", uploadHash,
      is(equalTo(downloadedHash)));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:33,代码来源:AmazonClientUploadIT.java

示例8: multipartCopy

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
/**
 * Verifies multipart copy.
 *
 * @throws InterruptedException
 */
@Test
public void multipartCopy() throws InterruptedException, IOException, NoSuchAlgorithmException {
  final int contentLen = 3 * _1MB;

  final ObjectMetadata objectMetadata = new ObjectMetadata();
  objectMetadata.setContentLength(contentLen);

  final String assumedSourceKey = UUID.randomUUID().toString();

  final Bucket sourceBucket = s3Client.createBucket(UUID.randomUUID().toString());
  final Bucket targetBucket = s3Client.createBucket(UUID.randomUUID().toString());

  final TransferManager transferManager = createTransferManager(_2MB, _1MB, _2MB, _1MB);

  final InputStream sourceInputStream = randomInputStream(contentLen);
  final Upload upload = transferManager
      .upload(sourceBucket.getName(), assumedSourceKey,
          sourceInputStream, objectMetadata);

  final UploadResult uploadResult = upload.waitForUploadResult();

  assertThat(uploadResult.getKey(), is(assumedSourceKey));

  final String assumedDestinationKey = UUID.randomUUID().toString();
  final Copy copy =
      transferManager.copy(sourceBucket.getName(), assumedSourceKey, targetBucket.getName(),
          assumedDestinationKey);
  final CopyResult copyResult = copy.waitForCopyResult();
  assertThat(copyResult.getDestinationKey(), is(assumedDestinationKey));

  final S3Object copiedObject = s3Client.getObject(targetBucket.getName(), assumedDestinationKey);

  assertThat("Hashes for source and target S3Object do not match.",
      HashUtil.getDigest(copiedObject.getObjectContent()) + "-1",
      is(uploadResult.getETag()));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:42,代码来源:AmazonClientUploadIT.java

示例9: nuevoAnuncio

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
@RequestMapping("/anuncio/nuevo")
public String nuevoAnuncio(Model model, 
		@RequestParam String nombre,
		@RequestParam String asunto,
		@RequestParam String comentario,
		@RequestParam String filename,
		@RequestParam MultipartFile file) {

       if (!file.isEmpty()) {
           try {
               ObjectMetadata objectMetadata = new ObjectMetadata();
               objectMetadata.setContentType(file.getContentType());

               TransferManager transferManager = new TransferManager(s3);
               transferManager.upload(bucket, filename, file.getInputStream(), objectMetadata);
               
           } catch (Exception e) {
           	model.addAttribute("message", "You failed to upload " + filename + " => " + e.getMessage());
               return "error";
           }
       } else {
       	model.addAttribute("message", "You failed to upload " + filename + " because the file was empty.");
           return "error";
       }

       Anuncio anuncio = new Anuncio(nombre, asunto, comentario);
       anuncio.setFoto(s3.getUrl(bucket, filename));

	repository.save(anuncio);

       return "anuncio_guardado";

}
 
开发者ID:codeurjc,项目名称:spring-cloud-aws-sample,代码行数:34,代码来源:TablonController.java

示例10: store

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
@Override
public void store(File file) throws Exception {
       
	LogUtils.debug(LOG_TAG, "Uploading new file. Name: " + file.getName());
       TransferManager tm = new TransferManager(new DefaultAWSCredentialsProviderChain());
       // TransferManager processes all transfers asynchronously, 
       // so this call will return immediately.
       Upload upload = tm.upload(bucketName, file.getName(), file);
       upload.waitForCompletion();
       LogUtils.debug(LOG_TAG, "Successfully uploaded file to bucket.\nName: " + file.getName() + "\nBucket name: " +
               bucketName);
       tm.shutdownNow();
}
 
开发者ID:darshanmaiya,项目名称:MCSFS,代码行数:14,代码来源:S3Store.java

示例11: transferFileToS3

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
private void transferFileToS3(final String key) {
	final long fileSizeMb = file.length() / (1024 * 1024);
	getLogger().info("Uploading {} MB from file {} to {}", fileSizeMb, file, getS3Url());
	final TransferManager transferManager = createTransferManager();
	final Instant start = Instant.now();
	final Upload upload = transferManager.upload(config.getDeploymentBucket(), key, file);
	try {
		upload.waitForCompletion();
		getLogger().info("Uploaded {} to {} in {}", file, getS3Url(), Duration.between(start, Instant.now()));
	} catch (final InterruptedException e) {
		Thread.currentThread().interrupt();
		throw new AssertionError("Upload interrupted", e);
	}
}
 
开发者ID:kaklakariada,项目名称:aws-sam-gradle,代码行数:15,代码来源:S3UploadTask.java

示例12: uploadFile

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
public static void uploadFile(String file_path, String bucket_name,
        String key_prefix, boolean pause)
{
    System.out.println("file: " + file_path +
            (pause ? " (pause)" : ""));

    String key_name = null;
    if (key_prefix != null) {
        key_name = key_prefix + '/' + file_path;
    } else {
        key_name = file_path;
    }

    File f = new File(file_path);
    TransferManager xfer_mgr = new TransferManager();
    try {
        Upload xfer = xfer_mgr.upload(bucket_name, key_name, f);
        // loop with Transfer.isDone()
        XferMgrProgress.showTransferProgress(xfer);
        //  or block with Transfer.waitForCompletion()
        XferMgrProgress.waitForCompletion(xfer);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    xfer_mgr.shutdownNow();
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:28,代码来源:XferMgrUpload.java

示例13: uploadFileAsync

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
@Override
public Upload uploadFileAsync(final String bucketName, final String fileName, final File fileObj,
		final CannedAccessControlList cannedAcl) throws AmazonClientException, AmazonServiceException, IOException {
	LOGGER.info("uploadObjectAsync invoked, bucketName: {} , fileName: {} and cannedAccessControlList: {}", bucketName, fileName, cannedAcl);
	final PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, fileObj).withCannedAcl(cannedAcl);
	final TransferManager transferMgr = new TransferManager(s3client);
	return transferMgr.upload(putObjectRequest);
}
 
开发者ID:abhinavmishra14,项目名称:aws-s3-utils,代码行数:9,代码来源:AwsS3IamServiceImpl.java

示例14: store

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
@Override
public F.Promise<Void> store(Path path, String key, String name) {
    Promise<Void> promise = Futures.promise();

    TransferManager transferManager = new TransferManager(credentials);
    try {
        Upload upload = transferManager.upload(bucketName, key, path.toFile());
        upload.addProgressListener((ProgressListener) progressEvent -> {
            if (progressEvent.getEventType().isTransferEvent()) {
                if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_COMPLETED_EVENT)) {
                    transferManager.shutdownNow();
                    promise.success(null);
                } else if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_FAILED_EVENT)) {
                    transferManager.shutdownNow();
                    logger.error(progressEvent.toString());
                    promise.failure(new Exception(progressEvent.toString()));
                }
            }
        });
    } catch (AmazonServiceException ase) {
        logAmazonServiceException (ase);
    } catch (AmazonClientException ace) {
        logAmazonClientException(ace);
    }

    return F.Promise.wrap(promise.future());
}
 
开发者ID:thunderbit,项目名称:thunderbit,代码行数:28,代码来源:AmazonS3Storage.java

示例15: uploadFileToS3

import com.amazonaws.services.s3.transfer.TransferManager; //导入方法依赖的package包/类
/**
 * Uploads a file to S3 and returns the s3 file key.  The bucket that is used is configured the properties file via
 * s3.bucket
 *
 * @param s3Bucket the s3 bucket name
 * @param localFile the local file to be uploaded
 * @param s3FileKey the s3 file key that should be used
 * @return a 2-element array, where element 0 is the s3 bucket and element 1 is the s3 file key
 */
public String[] uploadFileToS3(String s3Bucket, final Path localFile, final String s3FileKey)
        throws IOException, InterruptedException {
    if (localFile == null) {
        throw new NullPointerException("localFile was null.");
    }
    if (isEmpty(s3FileKey)) {
        throw new NullPointerException("objectFileKey cannot be null");
    }
    if (logger.isTraceEnabled()) {
        logger.trace(format("uploadFileToS3(%s)", localFile.getFileName().toString()));
    }
    AWSCredentials awsCredentials = AmazonAWSHelper.getCredentials();
    TransferManager tx = new TransferManager(awsCredentials);

    ObjectMetadata metadata = new ObjectMetadata();
    final String contentType = detectContentTypeFromFilename(s3FileKey);
    if (logger.isDebugEnabled()) {
        logger.debug(format("Setting contentType to '%s' in metadata for S3 object '%s'", contentType, s3FileKey));
    }
    metadata.setContentType(contentType);
    Upload myUpload = tx.upload(s3Bucket, s3FileKey, Files.newInputStream(localFile), metadata);

    myUpload.waitForCompletion();

    String[] retval = {s3Bucket, s3FileKey};
    if (logger.isDebugEnabled()) {
        logger.debug(format("Upload to S3 was successful.  bucket: '%s', file key: '%s'", s3Bucket, s3FileKey));
    }
    return retval;
}
 
开发者ID:srinikandula,项目名称:mybus,代码行数:40,代码来源:AWSClient.java


注:本文中的com.amazonaws.services.s3.transfer.TransferManager.upload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。