.contentMD5(Files.hash( ephemeral, Hashing.md5() )) .contentType("application/json");
.contentMD5(Files.hash( uploadFile, Hashing.md5())) .contentType( "application/json" );
builder = builder.contentMD5(contentMD5);
@Override public void testMetadata() throws InterruptedException, IOException { String name = "hello"; HashFunction hf = Hashing.md5(); HashCode md5 = hf.newHasher().putString(TEST_STRING, Charsets.UTF_8).hash(); Blob blob = view.getBlobStore().blobBuilder(name).userMetadata(ImmutableMap.of("adrian", "powderpuff")) .payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN).contentMD5(md5).build(); String container = getContainerName(); try { assertNull(view.getBlobStore().blobMetadata(container, "powderpuff")); addBlobToContainer(container, blob); Blob newObject = validateContent(container, name); BlobMetadata metadata = newObject.getMetadata(); validateMetadata(metadata); validateMetadata(metadata, container, name); validateMetadata(view.getBlobStore().blobMetadata(container, name)); blob.getMetadata().getUserMetadata().put("adrian", "wonderpuff"); blob.getMetadata().getUserMetadata().put("adrian", "powderpuff"); addBlobToContainer(container, blob); validateMetadata(view.getBlobStore().blobMetadata(container, name)); } finally { returnContainer(container); } }
@Test public void testListContainerWithZeroMaxResults() throws Exception { String key = "hello"; String containerName = getContainerName(); try { addBlobToContainer(containerName, // NOTE all metadata in jclouds comes out as lowercase, in an effort to // normalize the providers. view.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff")) .payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN) .contentMD5(md5().hashString(TEST_STRING, UTF_8).asBytes()) .build()); awaitConsistency(); validateContent(containerName, key); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName, maxResults(0)); assertThat(container).isEmpty(); } finally { returnContainer(containerName); } }
@Test(groups = "live") public void testPutBlobWithMd5() throws IOException, InterruptedException { String containerName = getContainerName(); String blobName = "md5test"; try { long contentLength = 32 * 1024L; ByteSource byteSource = TestUtils.randomByteSource().slice(0, contentLength); ByteSourcePayload payload = Payloads.newByteSourcePayload(byteSource); PayloadEnclosingImpl payloadImpl = new PayloadEnclosingImpl(payload); BlobStore blobStore = view.getBlobStore(); // This would trigger server side validation of md5 HashCode hcMd5 = byteSource.hash(Hashing.md5()); Blob blob = blobStore.blobBuilder(blobName).payload(payloadImpl.getPayload()).contentType("image/jpeg") .contentLength(contentLength).contentLanguage("en").contentDisposition("attachment") .contentMD5(hcMd5).userMetadata(ImmutableMap.of("Adrian", "powderpuff")).build(); blobStore.putBlob(containerName, blob); checkMD5(containerName, blobName, hcMd5.asBytes()); } finally { returnContainer(containerName); } } }
@Test public void testListMarkerAfterLastKey() throws Exception { String key = "hello"; String containerName = getContainerName(); try { addBlobToContainer(containerName, // NOTE all metadata in jclouds comes out as lowercase, in an effort to // normalize the providers. view.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff")) .payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN) .contentMD5(md5().hashString(TEST_STRING, UTF_8).asBytes()) .build()); validateContent(containerName, key); awaitConsistency(); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName, afterMarker(key)); assertThat(container).isEmpty(); } finally { returnContainer(containerName); } }
public void testSignPutBlobWithGenerate() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, NoSuchMethodException, IOException { ByteSource byteSource = ByteSource.wrap("foo".getBytes(Charsets.UTF_8)); Blob blob = blobFactory.get().name(blobName) .payload(byteSource) .contentLength(byteSource.size()) .contentMD5(byteSource.hash(Hashing.md5()).asBytes()) .contentType("text/plain").build(); byte[] md5 = { -84, -67, 24, -37, 76, -62, -8, 92, -19, -17, 101, 79, -52, -60, -92, -40 }; assertEquals(blob.getPayload().getContentMetadata().getContentMD5(), md5); HttpRequest request = signer.signPutBlob(containerName, blob); assertRequestLineEquals(request, "PUT " + fullUrl + " HTTP/1.1"); assertNonPayloadHeadersEqual( request, "Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\nContent-Length: 3\nContent-MD5: rL0Y20zC+Fzt72VPzMSk2A==\nContent-Type: text/plain\n"); assertContentHeadersEqual(request, "text/plain", null, null, null, 3L, md5, null); assertEquals(request.getFilters().size(), 0); }
@Test @Parameters( { "jclouds.blobstore.httpstream.url", "jclouds.blobstore.httpstream.md5" }) public void testCopyUrl(@Optional String httpStreamUrl, @Optional String httpStreamMD5) throws Exception { httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl : sysHttpStreamUrl, "httpStreamUrl"); httpStreamMD5 = checkNotNull(httpStreamMD5 != null ? httpStreamMD5 : sysHttpStreamMD5, "httpStreamMd5"); HttpResponse response = view.utils().http().invoke(HttpRequest.builder().method("GET").endpoint(httpStreamUrl).build()); long length = response.getPayload().getContentMetadata().getContentLength(); String name = "hello"; byte[] md5 = base16().lowerCase().decode(httpStreamMD5); Blob blob = view.getBlobStore().blobBuilder(name).payload(response.getPayload()).contentLength(length) .contentMD5(md5).build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); checkMD5(container, name, md5); } finally { returnContainer(container); } }
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, NoSuchMethodException, IOException { HashCode hashCode = HashCode.fromBytes(new byte[16]); Blob blob = blobFactory.get().name(blobName).forSigning().contentLength(2L).contentMD5(hashCode) .contentType("text/plain").build(); assertEquals(blob.getPayload().getContentMetadata().getContentMD5AsHashCode(), hashCode); HttpRequest request = signer.signPutBlob(containerName, blob); assertRequestLineEquals(request, "PUT " + fullUrl + " HTTP/1.1"); assertNonPayloadHeadersEqual( request, "Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n" + "Content-Length: 2\n" + "Content-MD5: AAAAAAAAAAAAAAAAAAAAAA==\n" + "Content-Type: text/plain\n"); assertContentHeadersEqual(request, "text/plain", null, null, null, 2L, hashCode.asBytes(), null); assertEquals(request.getFilters().size(), 0); }
@Test @Parameters( { "jclouds.blobstore.httpstream.url", "jclouds.blobstore.httpstream.md5" }) public void testCopyUrl(@Optional String httpStreamUrl, @Optional String httpStreamMD5) throws Exception { httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl : sysHttpStreamUrl, "httpStreamUrl"); httpStreamMD5 = checkNotNull(httpStreamMD5 != null ? httpStreamMD5 : sysHttpStreamMD5, "httpStreamMd5"); HttpResponse response = view.utils().http().invoke(HttpRequest.builder().method("GET").endpoint(httpStreamUrl).build()); long length = response.getPayload().getContentMetadata().getContentLength(); String name = "hello"; byte[] md5 = base16().lowerCase().decode(httpStreamMD5); Blob blob = view.getBlobStore().blobBuilder(name).payload(response.getPayload()).contentLength(length) .contentMD5(md5).build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); checkMD5(container, name, md5); } finally { returnContainer(container); } }
private void putBlobWithMd5(byte[] payload, HashCode contentMD5) throws InterruptedException, IOException { String container = getContainerName(); BlobStore blobStore = view.getBlobStore(); try { String blobName = "putBlobWithMd5-" + new Random().nextLong(); Blob blob = blobStore .blobBuilder(blobName) .payload(payload) .contentMD5(contentMD5) .build(); blobStore.putBlob(container, blob); } finally { returnContainer(container); } }
@Test public void testSignPutBlob() throws Exception { HashCode hashCode = HashCode.fromBytes(new byte[16]); BlobStore signPutBlob = requestsSendResponses(init()); Blob blob = signPutBlob.blobBuilder("name").forSigning().contentLength(2L).contentMD5(hashCode) .contentType("text/plain").expires(new Date(1000)).build(); HttpRequest compare = putBlob(); compare.setPayload(blob.getPayload()); assertEquals(signPutBlob.getContext().getSigner().signPutBlob(container, blob), compare); }
private void uploadByteSource(String container, String name, ByteSource byteSource) throws IOException { BlobStore blobStore = view.getBlobStore(); blobStore.putBlob(container, blobStore.blobBuilder(name) .payload(new ByteSourcePayload(byteSource)) .contentType("text/plain") .contentMD5(byteSource.hash(md5())) .contentLength(byteSource.size()) .build()); }
private Blob createBlob( FileResource fileResource, File file ) { return blobStore.blobBuilder( fileResource.getStorageKey() ) .payload( file ) .contentLength( fileResource.getContentLength() ) .contentMD5( HashCode.fromString( fileResource.getContentMd5() ) ) .contentType( fileResource.getContentType() ) .contentDisposition( "filename=" + fileResource.getName() ) .build(); }
public void testMultipartChunkedFileStream() throws IOException, InterruptedException { Files.copy(oneHundredOneConstitutions, new File("target/const.txt")); String containerName = getContainerName(); try { BlobStore blobStore = view.getBlobStore(); blobStore.createContainerInLocation(null, containerName); Blob blob = blobStore.blobBuilder("const.txt") .payload(new File("target/const.txt")).contentMD5(oneHundredOneConstitutionsMD5).build(); blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart()); } finally { returnContainer(containerName); } } }
private Blob createBlob( FileResource fileResource, byte[] bytes ) { return blobStore.blobBuilder( fileResource.getStorageKey() ) .payload( bytes ) .contentLength( fileResource.getContentLength() ) .contentMD5( HashCode.fromString( fileResource.getContentMd5() ) ) .contentType( fileResource.getContentType() ) .contentDisposition( "filename=" + fileResource.getName() ) .build(); }
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, NoSuchMethodException, IOException { Blob blob = blobFactory.get().name(blobName).forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 }) .contentType("text/plain").build(); assertEquals(blob.getPayload().getContentMetadata().getContentMD5(), new byte[] { 0, 2, 4, 8 }); HttpRequest request = signer.signPutBlob(containerName, blob); assertRequestLineEquals(request, "PUT " + fullUrl + " HTTP/1.1"); assertNonPayloadHeadersEqual( request, "Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\nContent-Length: 2\nContent-MD5: AAIECA==\nContent-Type: text/plain\n"); assertContentHeadersEqual(request, "text/plain", null, null, null, 2L, new byte[] { 0, 2, 4, 8 }, null); assertEquals(request.getFilters().size(), 0); }
@Test public void testSignPutBlob() throws Exception { BlobStore signPutBlob = requestsSendResponses(init()); Blob blob = signPutBlob.blobBuilder("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 }) .contentType("text/plain").expires(new Date(1000)).build(); HttpRequest compare = putBlob(); compare.setPayload(blob.getPayload()); assertEquals(signPutBlob.getContext().getSigner().signPutBlob(container, blob), compare); }
private void uploadConstitution(String container, String name, String contentDisposition) throws IOException { view.getBlobStore().putBlob( container, view.getBlobStore().blobBuilder(name).payload(oneHundredOneConstitutions.getInput()).contentType( "text/plain").contentMD5(oneHundredOneConstitutionsMD5).contentLength( oneHundredOneConstitutionsLength).contentDisposition(contentDisposition).build()); }