import java.security.MessageDigest import com.microsoft.windowsazure.services.core.storage.utils.Base64; import com.google.common.io.Files String putFile(String remoteFolder, String filePath){ File fileReference = new File (filePath) // the user is already authentificated and the container is not null CloudBlockBlob blob = container.getBlockBlobReference(remoteFolderName+"/"+filePath); FileInputStream fis = new FileInputStream(fileReference) if(blob){ BlobProperties props = blob.getProperties() MessageDigest md5digest = MessageDigest.getInstance("MD5") String md5 = Base64.encode(Files.getDigest(fileReference, md5digest)) props.setContentMD5(md5) blob.setProperties(props) blob.upload(fis, fileReference.length()) return fileReference.getName() }else{ //ErrorHandling return "" } }
blobProperties.setContentMD5(mds); ByteArrayInputStream bin = new ByteArrayInputStream(f); blob.upload(bin, csz, null, null, opContext); blobProperties.setContentMD5(base64EncodedMD5content);
/** * Commits the blob, for block blob this uploads the block list. * * @throws StorageException * An exception representing any error which occurred during the operation. */ @DoesServiceRequest private synchronized void commit() throws StorageException { if (this.options.getStoreBlobContentMD5()) { this.parentBlobRef.getProperties().setContentMD5(Base64.encode(this.md5Digest.digest())); } if (this.streamType == BlobType.BLOCK_BLOB) { // wait for all blocks to finish final CloudBlockBlob blobRef = (CloudBlockBlob) this.parentBlobRef; blobRef.commitBlockList(this.blockList, this.accessCondition, this.options, this.opContext); } else if (this.options.getStoreBlobContentMD5()) { this.parentBlobRef.uploadProperties(this.accessCondition, this.options, this.opContext); } }
/** * Commits the blob, for block blob this uploads the block list. * * @throws StorageException * An exception representing any error which occurred during the operation. */ @DoesServiceRequest private synchronized void commit() throws StorageException { if (this.options.getStoreBlobContentMD5()) { this.parentBlobRef.getProperties().setContentMD5(Base64.encode(this.md5Digest.digest())); } if (this.streamType == BlobType.BLOCK_BLOB) { // wait for all blocks to finish final CloudBlockBlob blobRef = (CloudBlockBlob) this.parentBlobRef; blobRef.commitBlockList(this.blockList, this.accessCondition, this.options, this.opContext); } else if (this.options.getStoreBlobContentMD5()) { this.parentBlobRef.uploadProperties(this.accessCondition, this.options, this.opContext); } }
properties.setContentMD5(request.getHeaderField(BlobConstants.BLOB_CONTENT_MD5_HEADER)); properties.setContentMD5(request.getHeaderField(Constants.HeaderConstants.CONTENT_MD5));
this.properties.setContentMD5(value);
this.properties.setContentMD5(value);
properties.setContentMD5(request.getHeaderField(BlobConstants.BLOB_CONTENT_MD5_HEADER)); properties.setContentMD5(request.getHeaderField(Constants.HeaderConstants.CONTENT_MD5));
case md5: try { blob.getProperties().setContentMD5(Base64.toBase64String(Hex.decodeHex(status.getChecksum().hash.toCharArray()))); headers.remove(HttpHeaders.CONTENT_MD5);
this.properties.setContentMD5(descriptor.getMd5());
this.properties.setContentMD5(descriptor.getMd5());
public static void setBlobProperties(CloudBlob blob) { blob.getProperties().setCacheControl("no-transform"); blob.getProperties().setContentDisposition("attachment"); blob.getProperties().setContentEncoding("gzip"); blob.getProperties().setContentLanguage("tr,en"); blob.getProperties().setContentMD5("MDAwMDAwMDA="); blob.getProperties().setContentType("text/html"); }
source.getMetadata().put("Test", "newvalue"); source.uploadMetadata(); source.getProperties().setContentMD5(null); source.upload(stream2, buffer.length);
source.getMetadata().put("Test", "newvalue"); source.uploadMetadata(); source.getProperties().setContentMD5(null); source.upload(stream2, buffer.length);
@Test public void testBlobUploadWithoutMD5Validation() throws URISyntaxException, StorageException, IOException { final String appendBlobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testAppendBlob"); final CloudAppendBlob appendBlobRef = this.container .getAppendBlobReference(appendBlobName); final int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper .getRandomDataStream(length); BlobRequestOptions options = new BlobRequestOptions(); options.setDisableContentMD5Validation(false); options.setStoreBlobContentMD5(false); appendBlobRef.upload(srcStream, length, null, options, null); appendBlobRef.downloadAttributes(); appendBlobRef.getProperties().setContentMD5("MDAwMDAwMDA="); appendBlobRef.uploadProperties(null, options, null); try { appendBlobRef.download(new ByteArrayOutputStream(), null, options, null); fail(); } catch (StorageException ex) { assertEquals(306, ex.getHttpStatusCode()); assertEquals("InvalidMd5", ex.getErrorCode()); } options.setDisableContentMD5Validation(true); appendBlobRef .download(new ByteArrayOutputStream(), null, options, null); }
@Test public void testBlobUploadWithoutMD5Validation() throws URISyntaxException, StorageException, IOException { final String pageBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testPageBlob"); final CloudPageBlob pageBlobRef = this.container.getPageBlobReference(pageBlobName); final int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); BlobRequestOptions options = new BlobRequestOptions(); options.setDisableContentMD5Validation(false); options.setStoreBlobContentMD5(false); pageBlobRef.upload(srcStream, length, null, options, null); pageBlobRef.downloadAttributes(); pageBlobRef.getProperties().setContentMD5("MDAwMDAwMDA="); pageBlobRef.uploadProperties(null, options, null); try { pageBlobRef.download(new ByteArrayOutputStream(), null, options, null); fail(); } catch (StorageException ex) { assertEquals(306, ex.getHttpStatusCode()); assertEquals("InvalidMd5", ex.getErrorCode()); } options.setDisableContentMD5Validation(true); pageBlobRef.download(new ByteArrayOutputStream(), null, options, null); final CloudPageBlob pageBlobRef2 = this.container.getPageBlobReference(pageBlobName); assertNull(pageBlobRef2.getProperties().getContentMD5()); byte[] target = new byte[4]; pageBlobRef2.downloadRangeToByteArray(0L, 4L, target, 0); assertEquals("MDAwMDAwMDA=", pageBlobRef2.properties.getContentMD5()); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testBlobUploadWithoutMD5Validation() throws URISyntaxException, StorageException, IOException { final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); final CloudBlockBlob blockBlobRef = this.container.getBlockBlobReference(blockBlobName); final int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); BlobRequestOptions options = new BlobRequestOptions(); options.setDisableContentMD5Validation(false); options.setStoreBlobContentMD5(false); blockBlobRef.upload(srcStream, -1, null, options, null); blockBlobRef.downloadAttributes(); blockBlobRef.getProperties().setContentMD5("MDAwMDAwMDA="); blockBlobRef.uploadProperties(null, options, null); try { blockBlobRef.download(new ByteArrayOutputStream(), null, options, null); fail(); } catch (StorageException ex) { assertEquals(306, ex.getHttpStatusCode()); assertEquals("InvalidMd5", ex.getErrorCode()); } options.setDisableContentMD5Validation(true); blockBlobRef.download(new ByteArrayOutputStream(), null, options, null); final CloudBlockBlob blockBlobRef2 = this.container.getBlockBlobReference(blockBlobName); assertNull(blockBlobRef2.getProperties().getContentMD5()); byte[] target = new byte[4]; blockBlobRef2.downloadRangeToByteArray(0L, 4L, target, 0); assertEquals("MDAwMDAwMDA=", blockBlobRef2.properties.getContentMD5()); }
source.getMetadata().put("Test", "newvalue"); source.uploadMetadata(); source.getProperties().setContentMD5(null); source.uploadText(newData, Constants.UTF8_CHARSET, null, null, null);