@Override public StorageObject upload(final Path file, Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback prompt) throws BackgroundException { if(status.getLength() > multipartThreshold) { if(!preferences.getBoolean("s3.upload.multipart")) { log.warn("Multipart upload is disabled with property s3.upload.multipart"); // Disabled by user if(status.getLength() < preferences.getLong("s3.upload.multipart.required.threshold")) { // Use single upload service return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } } try { return new S3MultipartUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } catch(NotfoundException | InteroperabilityException e) { log.warn(String.format("Failure using multipart upload %s. Fallback to single upload.", e.getMessage())); } } // Use single upload service return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); }
@Override protected void post(final Path file, final MessageDigest digest, final StorageObject part) throws BackgroundException { if(null != part.getServerSideEncryptionAlgorithm()) { log.warn(String.format("Skip checksum verification for %s with server side encryption enabled", file)); return; } this.verify(file, digest, Checksum.parse(part.getETag())); }
return (T) new S3SingleUploadService(this, new S3WriteFeature(this, new S3DisabledMultipartService()));
@Override public StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final S3Protocol.AuthenticationHeaderSignatureVersion signatureVersion = session.getSignatureVersion(); switch(signatureVersion) { case AWS4HMACSHA256: if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).compute(local.getInputStream(), status)); } break; } try { return super.upload(file, local, throttle, listener, status, callback); } catch(InteroperabilityException e) { if(!session.getSignatureVersion().equals(signatureVersion)) { // Retry if upload fails with Header "x-amz-content-sha256" set to the hex-encoded SHA256 hash of the // request payload is required for AWS Version 4 request signing return this.upload(file, local, throttle, listener, status, callback); } throw e; } }