本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlobClient类的典型用法代码示例。如果您正苦于以下问题:Java CloudBlobClient类的具体用法?Java CloudBlobClient怎么用?Java CloudBlobClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CloudBlobClient类属于com.microsoft.azure.storage.blob包,在下文中一共展示了CloudBlobClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadToAzureStorage
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的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.CloudBlobClient; //导入依赖的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.CloudBlobClient; //导入依赖的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: setupContainer
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的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;
}
}
示例5: createClient
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的package包/类
void createClient(AzureStorageSettings azureStorageSettings) {
try {
logger.trace("creating new Azure storage client using account [{}], key [{}]",
azureStorageSettings.getAccount(), azureStorageSettings.getKey());
String storageConnectionString =
"DefaultEndpointsProtocol=https;"
+ "AccountName=" + azureStorageSettings.getAccount() + ";"
+ "AccountKey=" + azureStorageSettings.getKey();
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the blob client.
CloudBlobClient client = storageAccount.createCloudBlobClient();
// Register the client
this.clients.put(azureStorageSettings.getAccount(), client);
} catch (Exception e) {
logger.error("can not create azure storage client: {}", e.getMessage());
}
}
示例6: listBlobsByPrefix
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的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.CloudBlobClient; //导入依赖的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.CloudBlobClient; //导入依赖的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: getImageAsArray
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的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;
}
示例10: storeImage
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的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;
}
示例11: getImageAsArray
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的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;
}
示例12: storeImage
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的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;
}
示例13: primeRootContainer
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的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;
}
示例14: getCloudBlobContainer
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的package包/类
private CloudBlobContainer getCloudBlobContainer(String accountName, String accountKey, String containerName) {
CloudBlobContainer container = null;
if (StringUtils.isNotBlank(containerName)) {
final String storageConnectionString = "DefaultEndpointsProtocol=https"
+ ";AccountName=" + accountName
+ ";AccountKey=" + accountKey;
try {
final CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient serviceClient = account.createCloudBlobClient();
container = serviceClient.getContainerReference(containerName);
container.createIfNotExists();
} catch (StorageException | URISyntaxException | InvalidKeyException e) {
logger.error("Error connecting to container for account {} and container name {}", accountName, containerName, e);
}
}
return container;
}
示例15: getContainer
import com.microsoft.azure.storage.blob.CloudBlobClient; //导入依赖的package包/类
/**
* 获取容器
* @param blobClient Blob存储管理类
* @param containerName 容器名
*/
public static CloudBlobContainer getContainer(CloudBlobClient blobClient, String containerName) {
try {
//获取容器,如果容器不存在,则创建容器
CloudBlobContainer container = blobClient.getContainerReference(containerName);
container.createIfNotExists();
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
container.uploadPermissions(containerPermissions);
return container;
} catch (Exception e) {
DebugLog.e(TAG, "getContainer()", e);
return null;
}
}