在Java中读取Azure Blob存储区中文件的文件属性
下面是我使用
com.microsoft.azure.storage
图书馆
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." );
}
}
我正在寻找一个API,在这里,给定上传到Azure Blob商店的文件的文件路径,它可以返回该文件的属性,特别是上传的日期和时间
Java中是否有支持这一点的API
# 1 楼答案
您正在寻找的方法是^{} ,它} 的blob属性。它将包含关于blob的信息。你想在那里使用的方法是
返回类型为^{} 的对象将设置类型为^{getLastModified()
但是,这将返回上次更新blob的日期/时间。因此,如果您创建了一个blob,并且没有对其进行任何更改,那么可以使用此属性来确定它是何时上载的。但是,如果在创建blob后对其进行任何更改(如设置属性/元数据等),则返回的值是上次更改的日期/时间
如果您对查找blob是何时创建的感兴趣,您可能希望将此信息与blob一起存储为自定义元数据
你可以在这里获得关于SDK的详细信息:http://azure.github.io/azure-storage-java/