Java Code Examples for com.amazonaws.services.s3.transfer.TransferManagerBuilder#defaultTransferManager()

The following examples show how to use com.amazonaws.services.s3.transfer.TransferManagerBuilder#defaultTransferManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: S3UtilProgram.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static void downloadByFullPathAndFileNamePrefix(ParameterTool params) {
	final String bucket = params.getRequired("bucket");
	final String s3prefix = params.getRequired("s3prefix");
	final String localFolder = params.getRequired("localFolder");
	final String s3filePrefix = params.get("s3filePrefix", "");
	TransferManager tx = TransferManagerBuilder.defaultTransferManager();
	Predicate<String> keyPredicate = getKeyFilterByFileNamePrefix(s3filePrefix);
	KeyFilter keyFilter = s3filePrefix.isEmpty() ? KeyFilter.INCLUDE_ALL :
		objectSummary -> keyPredicate.test(objectSummary.getKey());
	try {
		tx.downloadDirectory(bucket, s3prefix, new File(localFolder), keyFilter).waitForCompletion();
	} catch (InterruptedException e) {
		System.out.println("Transfer interrupted");
	} finally {
		tx.shutdownNow();
	}
}
 
Example 2
Source File: S3UtilProgram.java    From flink with Apache License 2.0 6 votes vote down vote up
private static void downloadByFullPathAndFileNamePrefix(ParameterTool params) {
	final String bucket = params.getRequired("bucket");
	final String s3prefix = params.getRequired("s3prefix");
	final String localFolder = params.getRequired("localFolder");
	final String s3filePrefix = params.get("s3filePrefix", "");
	TransferManager tx = TransferManagerBuilder.defaultTransferManager();
	Predicate<String> keyPredicate = getKeyFilterByFileNamePrefix(s3filePrefix);
	KeyFilter keyFilter = s3filePrefix.isEmpty() ? KeyFilter.INCLUDE_ALL :
		objectSummary -> keyPredicate.test(objectSummary.getKey());
	try {
		tx.downloadDirectory(bucket, s3prefix, new File(localFolder), keyFilter).waitForCompletion();
	} catch (InterruptedException e) {
		System.out.println("Transfer interrupted");
	} finally {
		tx.shutdownNow();
	}
}
 
Example 3
Source File: S3UtilProgram.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void downloadFile(ParameterTool params) {
	final String bucket = params.getRequired("bucket");
	final String s3file = params.getRequired("s3file");
	final String localFile = params.getRequired("localFile");
	TransferManager tx = TransferManagerBuilder.defaultTransferManager();
	try {
		tx.download(bucket, s3file, new File(localFile)).waitForCompletion();
	} catch (InterruptedException e) {
		System.out.println("Transfer interrupted");
	} finally {
		tx.shutdownNow();
	}
}
 
Example 4
Source File: S3UtilProgram.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void downloadFile(ParameterTool params) {
	final String bucket = params.getRequired("bucket");
	final String s3file = params.getRequired("s3file");
	final String localFile = params.getRequired("localFile");
	TransferManager tx = TransferManagerBuilder.defaultTransferManager();
	try {
		tx.download(bucket, s3file, new File(localFile)).waitForCompletion();
	} catch (InterruptedException e) {
		System.out.println("Transfer interrupted");
	} finally {
		tx.shutdownNow();
	}
}
 
Example 5
Source File: TablonController.java    From spring-cloud-aws-sample with Apache License 2.0 5 votes vote down vote up
@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 = TransferManagerBuilder.defaultTransferManager();
               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";

}