本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlobContainer类的典型用法代码示例。如果您正苦于以下问题:Java CloudBlobContainer类的具体用法?Java CloudBlobContainer怎么用?Java CloudBlobContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CloudBlobContainer类属于com.microsoft.azure.storage.blob包,在下文中一共展示了CloudBlobContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadToAzureStorage
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
/**
* Upload image file to Azure storage with specified name.
*
* @param file image file object
* @param fileName specified file name
* @return relative path of the created image blob
*/
public String uploadToAzureStorage(ApplicationContext applicationContext, MultipartFile file, String fileName) {
String uri = null;
try {
CloudStorageAccount storageAccount =
(CloudStorageAccount) applicationContext.getBean("cloudStorageAccount");
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
setupContainer(blobClient, this.thumbnailImageContainer);
CloudBlobContainer originalImageContainer = setupContainer(blobClient, this.originalImageContainer);
if (originalImageContainer != null) {
CloudBlockBlob blob = originalImageContainer.getBlockBlobReference(fileName);
blob.upload(file.getInputStream(), file.getSize());
uri = blob.getUri().getPath();
}
} catch (Exception e) {
e.printStackTrace();
logger.error("Error uploading image: " + e.getMessage());
}
return uri;
}
示例2: deleteFiles
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
@Override
public void deleteFiles(String account, LocationMode mode, String container, String path) throws URISyntaxException, StorageException {
logger.trace("delete files container [{}], path [{}]", container, path);
// Container name must be lower case.
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
SocketAccess.doPrivilegedVoidException(() -> {
if (blobContainer.exists()) {
// We list the blobs using a flat blob listing mode
for (ListBlobItem blobItem : blobContainer.listBlobs(path, true)) {
String blobName = blobNameFromUri(blobItem.getUri());
logger.trace("removing blob [{}] full URI was [{}]", blobName, blobItem.getUri());
deleteBlob(account, mode, container, blobName);
}
}
});
}
示例3: uploadPackageToAzureStorage
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
@Test
public void uploadPackageToAzureStorage() throws Exception {
final MSDeployArtifactHandlerImpl handler = new MSDeployArtifactHandlerImpl(mojo);
final CloudStorageAccount storageAccount = mock(CloudStorageAccount.class);
final CloudBlobClient blobClient = mock(CloudBlobClient.class);
doReturn(blobClient).when(storageAccount).createCloudBlobClient();
final CloudBlobContainer blobContainer = mock(CloudBlobContainer.class);
doReturn(blobContainer).when(blobClient).getContainerReference(anyString());
doReturn(true).when(blobContainer)
.createIfNotExists(any(BlobContainerPublicAccessType.class), isNull(), isNull());
final CloudBlockBlob blob = mock(CloudBlockBlob.class);
doReturn(blob).when(blobContainer).getBlockBlobReference(anyString());
doNothing().when(blob).upload(any(FileInputStream.class), anyLong());
doReturn(new URI("http://blob")).when(blob).getUri();
final File file = new File("pom.xml");
final String packageUri = handler.uploadPackageToAzureStorage(file, storageAccount, "blob");
assertSame("http://blob", packageUri);
}
示例4: testRetryOn304
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
@Test
public void testRetryOn304() throws StorageException, IOException, URISyntaxException {
OperationContext operationContext = new OperationContext();
operationContext.getRetryingEventHandler().addListener(new StorageEvent<RetryingEvent>() {
@Override
public void eventOccurred(RetryingEvent eventArg) {
fail("Request should not be retried.");
}
});
CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
try {
container.create();
CloudBlockBlob blockBlobRef = (CloudBlockBlob) BlobTestHelper.uploadNewBlob(container, BlobType.BLOCK_BLOB,
"originalBlob", 1024, null);
AccessCondition accessCondition = AccessCondition.generateIfNoneMatchCondition(blockBlobRef.getProperties().getEtag());
blockBlobRef.download(new ByteArrayOutputStream(), accessCondition, null, operationContext);
fail("Download should fail with a 304.");
} catch (StorageException ex) {
assertEquals("The condition specified using HTTP conditional header(s) is not met.", ex.getMessage());
} finally {
container.deleteIfExists();
}
}
示例5: setupContainer
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
private CloudBlobContainer setupContainer(CloudBlobClient blobClient, String containerName) {
try {
CloudBlobContainer container = blobClient.getContainerReference(containerName);
if (!container.exists()) {
container.createIfNotExists();
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
container.uploadPermissions(containerPermissions);
}
return container;
} catch (Exception e) {
e.printStackTrace();
logger.error("Error setting up container: " + e.getMessage());
return null;
}
}
示例6: listBlobsByPrefix
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
@Override
public Map<String, BlobMetaData> listBlobsByPrefix(String account, LocationMode mode, String container, String keyPath, String prefix) throws URISyntaxException, StorageException {
// NOTE: this should be here: if (prefix == null) prefix = "";
// however, this is really inefficient since deleteBlobsByPrefix enumerates everything and
// then does a prefix match on the result; it should just call listBlobsByPrefix with the prefix!
logger.debug("listing container [{}], keyPath [{}], prefix [{}]", container, keyPath, prefix);
MapBuilder<String, BlobMetaData> blobsBuilder = MapBuilder.newMapBuilder();
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
SocketAccess.doPrivilegedVoidException(() -> {
if (blobContainer.exists()) {
for (ListBlobItem blobItem : blobContainer.listBlobs(keyPath + (prefix == null ? "" : prefix))) {
URI uri = blobItem.getUri();
logger.trace("blob url [{}]", uri);
// uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/
// this requires 1 + container.length() + 1, with each 1 corresponding to one of the /
String blobPath = uri.getPath().substring(1 + container.length() + 1);
CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobPath);
// fetch the blob attributes from Azure (getBlockBlobReference does not do this)
// this is needed to retrieve the blob length (among other metadata) from Azure Storage
blob.downloadAttributes();
BlobProperties properties = blob.getProperties();
String name = blobPath.substring(keyPath.length());
logger.trace("blob url [{}], name [{}], size [{}]", uri, name, properties.getLength());
blobsBuilder.put(name, new PlainBlobMetaData(name, properties.getLength()));
}
}
});
return blobsBuilder.immutableMap();
}
示例7: moveBlob
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
@Override
public void moveBlob(String account, LocationMode mode, String container, String sourceBlob, String targetBlob) throws URISyntaxException, StorageException {
logger.debug("moveBlob container [{}], sourceBlob [{}], targetBlob [{}]", container, sourceBlob, targetBlob);
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
CloudBlockBlob blobSource = blobContainer.getBlockBlobReference(sourceBlob);
if (blobSource.exists()) {
CloudBlockBlob blobTarget = blobContainer.getBlockBlobReference(targetBlob);
SocketAccess.doPrivilegedVoidException(() -> {
blobTarget.startCopy(blobSource);
blobSource.delete();
});
logger.debug("moveBlob container [{}], sourceBlob [{}], targetBlob [{}] -> done", container, sourceBlob, targetBlob);
}
}
示例8: setUpStorageAccount
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) {
try {
CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
// Create a blob service client
CloudBlobClient blobClient = account.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference(containerName);
container.createIfNotExists();
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
// Include public access in the permissions object
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
// Set the permissions on the container
container.uploadPermissions(containerPermissions);
return container;
} catch (StorageException | URISyntaxException | InvalidKeyException e) {
throw new RuntimeException(e);
}
}
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:19,代码来源:ManageLinuxWebAppStorageAccountConnection.java
示例9: deleteContainer
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
/**
* This method will remove the container from Azure Storage.
* @param containerName
* @return boolean
*/
public static boolean deleteContainer(String containerName )
{
if (ProjectUtil.isStringNullOREmpty(containerName)) {
ProjectLogger.log("Container name can't be null or empty");
return false;
}
CloudBlobContainer container =
AzureConnectionManager.getContainer(containerName, true);
if (container == null) {
ProjectLogger.log("Unable to get Azure contains object");
return false;
}
try {
boolean response = container.deleteIfExists();
if(!response) {
ProjectLogger.log("Container not found..");
}else {
ProjectLogger.log("Container is deleted===");
}
return true;
} catch (Exception e) {
ProjectLogger.log(e.getMessage(), e);
}
return false;
}
示例10: getImageAsArray
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
public byte[] getImageAsArray(String imagefilename) {
byte[] b = null;
CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
// Container name must be lower case.
CloudBlobContainer container;
try {
container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
CloudBlockBlob imgBlob = container.getBlockBlobReference(imagefilename);
b = downloadImage(imgBlob);
} catch (URISyntaxException | StorageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return result
return b;
}
示例11: storeImage
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
public String storeImage(String IncidentId, String fileName, String contentType, byte[] fileBuffer) {
CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
String imageUriString = null;
// Container name must be lower case.
CloudBlobContainer container;
try {
container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
container.createIfNotExists();
// Set anonymous access on the container.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
container.uploadPermissions(containerPermissions);
String incidentBlob = getIncidentBlobFilename(IncidentId,fileName);
CloudBlockBlob imgBlob = container.getBlockBlobReference(incidentBlob);
imgBlob.getProperties().setContentType(contentType);
imgBlob.uploadFromByteArray(fileBuffer, 0, fileBuffer.length);
imageUriString = incidentBlob;
} catch (URISyntaxException | StorageException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return result
return imageUriString;
}
示例12: getImageAsArray
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
public byte[] getImageAsArray(String imagefilename) {
byte[] b = null;
CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
// Container name must be lower case.
CloudBlobContainer container;
try {
container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
CloudBlockBlob imgBlob = container.getBlockBlobReference(imagefilename);
b = downloadImage(imgBlob);
} catch (URISyntaxException | StorageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return result
return b;
}
示例13: storeImage
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
public String storeImage(String IncidentId, String fileName, String contentType, byte[] fileBuffer) {
CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
String imageUriString = null;
// Container name must be lower case.
CloudBlobContainer container;
try {
container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
container.createIfNotExists();
// Set anonymous access on the container.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
container.uploadPermissions(containerPermissions);
String incidentBlob = getIncidentBlobFilename(IncidentId,fileName);
CloudBlockBlob imgBlob = container.getBlockBlobReference(incidentBlob);
imgBlob.getProperties().setContentType(contentType);
imgBlob.uploadFromByteArray(fileBuffer, 0, fileBuffer.length);
imageUriString = incidentBlob;
} catch (URISyntaxException | StorageException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return result
return imageUriString;
}
示例14: testContainerChecksWithSas
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
@Test
public void testContainerChecksWithSas() throws Exception {
testAccount = AzureBlobStorageTestAccount.create("",
EnumSet.of(CreateOptions.UseSas));
assumeNotNull(testAccount);
CloudBlobContainer container = testAccount.getRealContainer();
FileSystem fs = testAccount.getFileSystem();
// The container shouldn't be there
assertFalse(container.exists());
// A write should just fail
try {
fs.createNewFile(new Path("/foo"));
assertFalse("Should've thrown.", true);
} catch (AzureException ex) {
}
assertFalse(container.exists());
}
示例15: primeRootContainer
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入依赖的package包/类
private static CloudBlockBlob primeRootContainer(CloudBlobClient blobClient,
String accountName, String blobName, int fileSize) throws Exception {
// Create a container if it does not exist. The container name
// must be lower case.
CloudBlobContainer container = blobClient.getContainerReference("https://"
+ accountName + "/" + "$root");
container.createIfNotExists();
// Create a blob output stream.
CloudBlockBlob blob = container.getBlockBlobReference(blobName);
BlobOutputStream outputStream = blob.openOutputStream();
outputStream.write(new byte[fileSize]);
outputStream.close();
// Return a reference to the block blob object.
return blob;
}