Java Code Examples for com.amazonaws.services.s3.transfer.Upload#waitForCompletion()
The following examples show how to use
com.amazonaws.services.s3.transfer.Upload#waitForCompletion() .
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: S3Publisher.java From hollow-reference-implementation with Apache License 2.0 | 6 votes |
/** * Write a list of all of the state versions to S3. * @param newVersion */ private synchronized void updateSnapshotIndex(Long newVersion) { /// insert the new version into the list int idx = Collections.binarySearch(snapshotIndex, newVersion); int insertionPoint = Math.abs(idx) - 1; snapshotIndex.add(insertionPoint, newVersion); /// build a binary representation of the list -- gap encoded variable-length integers byte[] idxBytes = buidGapEncodedVarIntSnapshotIndex(); /// indicate the Content-Length ObjectMetadata metadata = new ObjectMetadata(); metadata.setHeader("Content-Length", (long)idxBytes.length); /// upload the new file content. try(InputStream is = new ByteArrayInputStream(idxBytes)) { Upload upload = s3TransferManager.upload(bucketName, getSnapshotIndexObjectName(blobNamespace), is, metadata); upload.waitForCompletion(); } catch(Exception e) { throw new RuntimeException(e); } }
Example 2
Source File: AWSUploader.java From halvade with GNU General Public License v3.0 | 6 votes |
public void Upload(String key, InputStream input, long size) throws InterruptedException { ObjectMetadata meta = new ObjectMetadata(); if(SSE) meta.setServerSideEncryption(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); meta.setContentLength(size); Upload upload = tm.upload(existingBucketName, key, input, meta); try { // Or you can block and wait for the upload to finish upload.waitForCompletion(); Logger.DEBUG("Upload complete."); } catch (AmazonClientException amazonClientException) { Logger.DEBUG("Unable to upload file, upload was aborted."); Logger.EXCEPTION(amazonClientException); } }
Example 3
Source File: Uploads.java From jobcacher-plugin with MIT License | 5 votes |
private void finishUploading(File file, Upload upload) throws InterruptedException { if (upload == null) { LOGGER.info("File: " + file.getName() + " already was uploaded"); return; } try { upload.waitForCompletion(); } finally { closeStream(file, openedStreams.remove(file)); } }
Example 4
Source File: S3Publisher.java From hollow-reference-implementation with Apache License 2.0 | 5 votes |
private void uploadFile(File file, String s3ObjectName, ObjectMetadata metadata) { try (InputStream is = new BufferedInputStream(new FileInputStream(file))) { Upload upload = s3TransferManager.upload(bucketName, s3ObjectName, is, metadata); upload.waitForCompletion(); } catch (Exception e) { throw new RuntimeException(e); } }
Example 5
Source File: FileController.java From full-teaching with Apache License 2.0 | 5 votes |
private void productionFileSaver(String keyName, String folderName, File f) throws InterruptedException { String bucketName = this.bucketAWS + "/" + folderName; TransferManager tm = new TransferManager(this.amazonS3); // TransferManager processes all transfers asynchronously, so this call will return immediately Upload upload = tm.upload(bucketName, keyName, f); try { // Or you can block and wait for the upload to finish upload.waitForCompletion(); System.out.println("Upload completed"); } catch (AmazonClientException amazonClientException) { System.out.println("Unable to upload file, upload was aborted."); amazonClientException.printStackTrace(); } }
Example 6
Source File: MultipartUpload.java From tutorials with MIT License | 5 votes |
public static void main(String[] args) throws Exception { String existingBucketName = "baeldung-bucket"; String keyName = "my-picture.jpg"; String filePath = "documents/my-picture.jpg"; AmazonS3 amazonS3 = AmazonS3ClientBuilder .standard() .withCredentials(new DefaultAWSCredentialsProviderChain()) .withRegion(Regions.DEFAULT_REGION) .build(); int maxUploadThreads = 5; TransferManager tm = TransferManagerBuilder .standard() .withS3Client(amazonS3) .withMultipartUploadThreshold((long) (5 * 1024 * 1024)) .withExecutorFactory(() -> Executors.newFixedThreadPool(maxUploadThreads)) .build(); ProgressListener progressListener = progressEvent -> System.out.println("Transferred bytes: " + progressEvent.getBytesTransferred()); PutObjectRequest request = new PutObjectRequest(existingBucketName, keyName, new File(filePath)); request.setGeneralProgressListener(progressListener); Upload upload = tm.upload(request); try { upload.waitForCompletion(); System.out.println("Upload complete."); } catch (AmazonClientException e) { System.out.println("Error occurred while uploading file"); e.printStackTrace(); } }