当前位置: 首页>>代码示例>>Java>>正文


Java CloudBlobContainer.createIfNotExists方法代码示例

本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists方法的典型用法代码示例。如果您正苦于以下问题:Java CloudBlobContainer.createIfNotExists方法的具体用法?Java CloudBlobContainer.createIfNotExists怎么用?Java CloudBlobContainer.createIfNotExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.microsoft.azure.storage.blob.CloudBlobContainer的用法示例。


在下文中一共展示了CloudBlobContainer.createIfNotExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
    }
}
 
开发者ID:Microsoft,项目名称:movie-db-java-on-azure,代码行数:18,代码来源:AzureStorageUploader.java

示例2: 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

示例3: 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;
  	
  }
 
开发者ID:Azure,项目名称:CityPower-Build-Sample,代码行数:26,代码来源:AzureImageStorageServiceImpl.java

示例4: 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;

}
 
开发者ID:Azure,项目名称:CityPower-Build-Sample,代码行数:26,代码来源:AzureImageStorageServiceImpl.java

示例5: 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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:AzureBlobStorageTestAccount.java

示例6: getCloudBlobContainer

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的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;
}
 
开发者ID:mesosphere,项目名称:dcos-cassandra-service,代码行数:22,代码来源:AzureStorageDriver.java

示例7: getContainer

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的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;
	}
}
 
开发者ID:leleliu008,项目名称:Newton_for_Android_AS,代码行数:22,代码来源:AzureStorage.java

示例8: Entry

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
/**
 * Ctor.
 * @param params Parameters
 * @param exit Exit criteria
 */
public Entry(final Params params, final Exit exit) {
    try {
        final CloudBlobContainer container = CloudStorageAccount.parse(
            new AzureStorageCredentials(
                params.account(), params.key(), true
            ).connectionString()
        ).createCloudBlobClient().getContainerReference(params.container());
        container.createIfNotExists();
        this.storage = new AuthenticatedStorage(
            params.username(), params.password(), params.realm(),
            new AzureBlobStorage(container)
        );
    } catch (final InvalidKeyException | URISyntaxException
            | StorageException e) {
        throw new IllegalStateException(e);
    }
    this.path = params.path();
    this.port = params.port();
    this.exit = exit;
}
 
开发者ID:carlosmiranda,项目名称:git-lfs-azureblob,代码行数:26,代码来源:Entry.java

示例9: createContainer

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
/**
 * Creates and returns a container for the sample application to use.
 *
 * @param blobClient CloudBlobClient object
 * @param containerName Name of the container to create
 * @return The newly created CloudBlobContainer object
 *
 * @throws StorageException
 * @throws RuntimeException
 * @throws IOException
 * @throws URISyntaxException
 * @throws IllegalArgumentException
 * @throws InvalidKeyException
 * @throws IllegalStateException
 */
private static CloudBlobContainer createContainer(CloudBlobClient blobClient, String containerName) throws StorageException, RuntimeException, IOException, InvalidKeyException, IllegalArgumentException, URISyntaxException, IllegalStateException {

    // Create a new container
    CloudBlobContainer container = blobClient.getContainerReference(containerName);
    try {
        if (container.createIfNotExists() == false) {
            throw new IllegalStateException(String.format("Container with name \"%s\" already exists.", containerName));
        }
    }
    catch (StorageException s) {
        if (s.getCause() instanceof java.net.ConnectException) {
            System.out.println("Caught connection exception from the client. If running with the default configuration please make sure you have started the storage emulator.");
        }
        throw s;
    }

    return container;
}
 
开发者ID:Azure-Samples,项目名称:storage-blob-java-getting-started,代码行数:34,代码来源:BlobBasics.java

示例10: validateWasbFileSystem

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的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");
        }
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:17,代码来源:AzureSetup.java

示例11: uploadImage

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public String uploadImage(String imageName, InputStream image, int imageLength) throws Exception {
    CloudBlobContainer container = getContainer();
    container.createIfNotExists();
    CloudBlockBlob imageBlob = container.getBlockBlobReference(imageName);
    imageBlob.getProperties().setContentType(CONTENT_TYPE);

    imageBlob.upload(image, imageLength);
    return getLink(imageName, container);

}
 
开发者ID:BANKEX,项目名称:smart-asset-iot-android-demo,代码行数:11,代码来源:ImageManager.java

示例12: createContainerIfNotExists

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
private void createContainerIfNotExists(String containerName) throws URISyntaxException, StorageException {
    // Create the blob client.
    final CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient();

    // Get a reference to a container.
    // The container name must be lower case
    final CloudBlobContainer container = blobClient.getContainerReference(containerName);

    // Create the container if it does not exist.
    container.createIfNotExists();
}
 
开发者ID:Microsoft,项目名称:azure-spring-boot,代码行数:12,代码来源:StorageSampleApplication.java

示例13: uploadFileAsBlob

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static String uploadFileAsBlob(final File fileToUpload, final CloudStorageAccount storageAccount,
                                      final String containerName, final String blobName) throws Exception {
    final CloudBlobContainer blobContainer = getBlobContainer(storageAccount, containerName);
    blobContainer.createIfNotExists(BlobContainerPublicAccessType.BLOB, null, null);

    final CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobName);
    blob.upload(new FileInputStream(fileToUpload), fileToUpload.length());
    return blob.getUri().toString();
}
 
开发者ID:Microsoft,项目名称:azure-maven-plugins,代码行数:10,代码来源:AzureStorageHelper.java

示例14: showBlob

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@RequestMapping(value = "/blob", method = RequestMethod.GET)
public @ResponseBody void showBlob(HttpServletResponse response)
{
	try
	{
		LOG.info("showBlob start");
		if (account == null)
		{
			account = factory.createAccountByServiceInstanceName("mystorage");
		}

		URL u = new URL(IMAGE_PATH);
		InputStream is = u.openStream();
		response.setContentType(MediaType.IMAGE_JPEG_VALUE);
		int imageSize = IOUtils.copy(is, response.getOutputStream());

		LOG.debug("Connecting to storage account...");
		CloudBlobClient serviceClient = account.createCloudBlobClient();

		// Container name must be lower case.
		CloudBlobContainer container = serviceClient.getContainerReference("myimages");
		container.createIfNotExists();

		// Upload an image file.
		LOG.debug("Uploading image...");
		CloudBlockBlob blob = container.getBlockBlobReference("image1.jpg");
		blob.upload(new URL(IMAGE_PATH).openStream(), imageSize);
		LOG.debug("Uploading image complete");

	} catch (Exception e)
	{
		LOG.error("Error processing request ", e);
	}
}
 
开发者ID:pivotal-partner-solution-architecture,项目名称:azure-service-broker-client,代码行数:35,代码来源:StorageRestController.java

示例15: getContainer

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
/**
 * This method will provide Azure CloudBlobContainer object or in case of error it will provide null;
 * 
 * @param containerName String
 * @return CloudBlobContainer or null
 */
public static CloudBlobContainer getContainer(String containerName , boolean isPublicAccess) {

  try {
    CloudBlobClient cloudBlobClient = getBlobClient();
    // Get a reference to a container , The container name must be lower case
    CloudBlobContainer container = cloudBlobClient
        .getContainerReference(containerName.toLowerCase(Locale.ENGLISH));
    // Create the container if it does not exist.
    boolean response = container.createIfNotExists();
    ProjectLogger.log("container creation done if not exist==" + response);
    // Create a permissions object.
    if(isPublicAccess) {
      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 (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
  }
  return null;
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:33,代码来源:AzureConnectionManager.java


注:本文中的com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。