@Test public void testUploadWithSHA256Checksum() throws Exception { final S3SingleUploadService service = new S3SingleUploadService(session, new S3WriteFeature(session, new S3DisabledMultipartService())); final Path container = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final String name = UUID.randomUUID().toString() + ".txt"; final Path test = new Path(container, name, EnumSet.of(Path.Type.file)); final Local local = new Local(System.getProperty("java.io.tmpdir"), name); final String random = new RandomStringGenerator.Builder().build().generate(1000); final OutputStream out = local.getOutputStream(false); IOUtils.write(random, out, Charset.defaultCharset()); out.close(); final TransferStatus status = new TransferStatus(); status.setLength(random.getBytes().length); status.setMime("text/plain"); service.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledLoginCallback()); assertTrue(new S3FindFeature(session).find(test)); final PathAttributes attributes = new S3AttributesFinderFeature(session).find(test); assertEquals(random.getBytes().length, attributes.getSize()); final Map<String, String> metadata = new S3MetadataFeature(session, new S3AccessControlListFeature(session)).getMetadata(test); assertFalse(metadata.isEmpty()); assertEquals("text/plain", metadata.get("Content-Type")); new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); local.delete(); }
@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(!HashAlgorithm.sha256.equals(status.getChecksum().algorithm)) { status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status)); } break; } try { return super.upload(file, local, throttle, listener, status, callback); } catch(InteroperabilityException e) { if(!session.getSignatureVersion().equals(signatureVersion)) { return this.upload(file, local, throttle, listener, status, callback); } throw e; } }
S3SingleUploadService extends HttpUploadFeature<StorageObject, MessageDigest> { @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(!HashAlgorithm.sha256.equals(status.getChecksum().algorithm)) { status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status)); } break; } try { return super.upload(file, local, throttle, listener, status, callback); } catch(InteroperabilityException e) { if(!session.getSignatureVersion().equals(signatureVersion)) { return this.upload(file, local, throttle, listener, status, callback); } throw e; } } }
S3SingleUploadService extends HttpUploadFeature<StorageObject, MessageDigest> { @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(!HashAlgorithm.sha256.equals(status.getChecksum().algorithm)) { status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status)); } break; } try { return super.upload(file, local, throttle, listener, status, callback); } catch(InteroperabilityException e) { if(!session.getSignatureVersion().equals(signatureVersion)) { return this.upload(file, local, throttle, listener, status, callback); } throw e; } } S3SingleUploadService(final S3Session session, final Write<StorageObject> writer); }
S3SingleUploadService extends HttpUploadFeature<StorageObject, MessageDigest> { @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(!HashAlgorithm.sha256.equals(status.getChecksum().algorithm)) { status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status)); } break; } try { return super.upload(file, local, throttle, listener, status, callback); } catch(InteroperabilityException e) { if(!session.getSignatureVersion().equals(signatureVersion)) { return this.upload(file, local, throttle, listener, status, callback); } throw e; } } S3SingleUploadService(final S3Session session, final Write<StorageObject> writer); @Override StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle,
                                final StreamListener listener, final TransferStatus status, final ConnectionCallback callback); @Override Upload<StorageObject> withWriter(final Write<StorageObject> writer); }
S3SingleUploadService extends HttpUploadFeature<StorageObject, MessageDigest> { @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(!HashAlgorithm.sha256.equals(status.getChecksum().algorithm)) { status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status)); } break; } try { return super.upload(file, local, throttle, listener, status, callback); } catch(InteroperabilityException e) { if(!session.getSignatureVersion().equals(signatureVersion)) { return this.upload(file, local, throttle, listener, status, callback); } throw e; } } S3SingleUploadService(final S3Session session, final Write<StorageObject> writer); @Override StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle,
                                final StreamListener listener, final TransferStatus status, final ConnectionCallback callback); @Override Upload<StorageObject> withWriter(final Write<StorageObject> writer);  }