Below is my code to upload a file to the Azure Blob Store using the
com.microsoft.azure.storage
library
public class BlobUploader {
private CloudBlobContainer blobContainer;
private static Logger LOGGER = LoggerFactory.getLogger(BlobUploader.class);
/**
* Constructor of the BlobUploader
*
* @param storageAccountName The storage account name where the files will be uploaded to.
* @param storageAccountKey The storage account key of the storage account
* @param containerName The container name where the files will be uploaded to.
*/
public BlobUploader( String storageAccountName, String storageAccountKey, String containerName ) {
String storageConnectionString = "DefaultEndpointsProtocol=http;AccountName=" + storageAccountName + ";AccountKey=" + storageAccountKey;
CloudStorageAccount storageAccount;
try {
storageAccount = CloudStorageAccount.parse( storageConnectionString );
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
// Retrieve reference to a previously created container.
this.blobContainer = blobClient.getContainerReference( containerName );
} catch ( Exception e ) {
LOGGER.error( "failed to construct blobUploader", e );
}
}
public void upload( String filePath ) throws Exception {
// Define the path to blob in the container
String blobPath = "/uploads";
File fileToBeUploaded = new File( filePath );
String fileName = fileToBeUploaded.getName();
String blobName = blobPath + fileName;
// Create or overwrite the blob with contents from a local file.
CloudBlockBlob blob = blobContainer.getBlockBlobReference( blobName );
System.out.println( "start uploading file " + filePath + " to blob " + blobName );
blob.upload( new FileInputStream( fileToBeUploaded ), fileToBeUploaded.length() );
System.out.println( "upload succeeded." );
}
}
I am looking for an API, where, given a file path to a file uploaded to the Azure Blob Store, it can return me the properties of that file, specifically, the date and time uploaded.
Is there an API in Java that supports this?