本文整理汇总了Java中com.microsoft.azure.storage.CloudStorageAccount.createCloudBlobClient方法的典型用法代码示例。如果您正苦于以下问题:Java CloudStorageAccount.createCloudBlobClient方法的具体用法?Java CloudStorageAccount.createCloudBlobClient怎么用?Java CloudStorageAccount.createCloudBlobClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.microsoft.azure.storage.CloudStorageAccount
的用法示例。
在下文中一共展示了CloudStorageAccount.createCloudBlobClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadToAzureStorage
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的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: createClient
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的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());
}
}
示例3: setUpStorageAccount
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的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
示例4: getCloudBlobContainer
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的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;
}
示例5: init
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
@Override
public void init() throws Exception {
super.init();
// Validate configuration
// Can throw IAEs
this.validateConfiguration();
try {
StorageCredentials credentials = new StorageCredentialsAccountAndKey(storage_account_name, storage_access_key);
CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, use_https);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
containerReference = blobClient.getContainerReference(container);
boolean created = containerReference.createIfNotExists();
if (created) {
log.info("Created container named '%s'.", container);
} else {
log.debug("Using existing container named '%s'.", container);
}
} catch (Exception ex) {
log.error("Error creating a storage client! Check your configuration.");
throw ex;
}
}
示例6: testCreateContainer
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
@Before
public void testCreateContainer() {
try {
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
// Get a reference to a container.
// The container name must be lower case
container = blobClient.getContainerReference(containerName);
// Create the container if it does not exist.
container.createIfNotExists();
} catch (Exception e) {
// Output the stack trace.
e.printStackTrace();
}
}
示例7: validateWasbFileSystem
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
private void validateWasbFileSystem(FileSystem fileSystem, String fileSystemType) throws URISyntaxException, InvalidKeyException, StorageException {
String accountName = fileSystem.getParameter(WasbFileSystemConfiguration.ACCOUNT_NAME, String.class);
String accountKey = fileSystem.getParameter(WasbFileSystemConfiguration.ACCOUNT_KEY, String.class);
String connectionString = "DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey;
CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer containerReference = blobClient.getContainerReference(TEST_CONTAINER + System.nanoTime());
try {
containerReference.createIfNotExists();
containerReference.delete();
} catch (StorageException e) {
if (e.getCause() instanceof UnknownHostException) {
throw new CloudConnectorException("The provided account does not belong to a valid storage account");
}
}
}
示例8: getContainer
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
private CloudBlobContainer getContainer() throws Exception {
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount
.parse(storageConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
Timber.d(blobClient.getEndpoint().toString());
// Get a reference to a container.
// The container name must be lower case
CloudBlobContainer container = blobClient.getContainerReference(CONTAINER_NAME);
return container;
}
示例9: setAzureBlobClient
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private void setAzureBlobClient(CloudStorageAccount azureStorageAccount) {
if (azureStorageAccount == null) {
log.error(LOGGER_KEY + "Azure storage account not available. Unable to Initialize Storage Client.");
return;
}
this.mBlobClient = azureStorageAccount.createCloudBlobClient();
}
示例10: getContainer
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
private static CloudBlobContainer getContainer() throws Exception {
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount
.parse(storageConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
// Get a reference to a container.
// The container name must be lower case
CloudBlobContainer container = blobClient.getContainerReference("images");
return container;
}
示例11: AzureStore
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
@SuppressWarnings("resource")
public AzureStore() throws InvalidKeyException, URISyntaxException,
StorageException, IOException {
FileReader fileReader = new FileReader("/secret/azure.key");
BufferedReader bufferedReader = new BufferedReader(fileReader);
String accountName = bufferedReader.readLine();
String accountKey = bufferedReader.readLine();
CloudStorageAccount account = CloudStorageAccount
.parse("DefaultEndpointsProtocol=http;" + "AccountName="
+ accountName + ";" + "AccountKey=" + accountKey);
CloudBlobClient serviceClient = account.createCloudBlobClient();
container = serviceClient
.getContainerReference(Constants.AZURE_CONTAINER_NAME);
container.createIfNotExists();
}
示例12: getFromAzureBlobStorage
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
public byte[] getFromAzureBlobStorage(String name) throws Exception {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(azureConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference(containerName);
CloudBlockBlob blob = container.getBlockBlobReference(name);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
blob.download(outStream);
byte[] image = outStream.toByteArray();
return image;
}
示例13: init
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
/**
* 初始化
* @return 初始化成功
*/
private synchronized boolean init() {
DebugLog.d(TAG, "init()");
if (blobClient != null && queueClient != null) {
return true;
}
//先查看缓存
Configuration configuration = null;
String azure = configuration.getAzureConf();
Charset charset = Charset.forName("utf-8");
String result = new String(SymmetricalEncryption.decrypt(Algorithm.AES, Base64.decode(azure.getBytes(charset)), MyApp.getApp().a().getBytes(charset)));
String[] result2 = result.split("\\|");
accountName = result2[0];
String key = result2[1];
CloudStorageAccount account = AzureStorage.getAccount(accountName, key);
if (account != null) {
blobClient = account.createCloudBlobClient();
queueClient = account.createCloudQueueClient();
}
DebugLog.d(TAG, "blobClient = " + blobClient);
DebugLog.d(TAG, "queueClient = " + queueClient);
return blobClient != null && queueClient != null;
}
示例14: getFromStorageAccount
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
public byte[] getFromStorageAccount(String name) throws Exception {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("images");
CloudBlockBlob blob = container.getBlockBlobReference(name);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
blob.download(outStream);
byte[] image = outStream.toByteArray();
return image;
}
示例15: getSchemaNames
import com.microsoft.azure.storage.CloudStorageAccount; //导入方法依赖的package包/类
@Override
public List<NamedThing> getSchemaNames(RuntimeContainer container) throws IOException {
List<NamedThing> result = new ArrayList<>();
try {
CloudStorageAccount storageAccount = getAzureConnection(container).getCloudStorageAccount();
CloudBlobClient client = storageAccount.createCloudBlobClient();
for (CloudBlobContainer c : client.listContainers()) {
result.add(new SimpleNamedThing(c.getName(), c.getName()));
}
} catch (InvalidKeyException | URISyntaxException e) {
throw new ComponentException(e);
}
return result;
}