public CloudBlobContainer getCloudBlobContainer(final String containerName) throws StorageException, URISyntaxException { CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName); cloudBlobContainer.createIfNotExists(); return cloudBlobContainer; }
@Override public void run() { try { CloudBlobContainer container = blobClient.getContainerReference(azureContainer); container.createIfNotExists(); CloudBlockBlob blob = container.getBlockBlobReference(azureKey); blob.upload(new java.io.FileInputStream(localFile), localFile.length()); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (StorageException e) { throw new RuntimeException(e); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } });
public void init() { try { String endpoint = String.format(ENDPOINT_TEMPLATE, configuration.getAccountName()); CloudStorageAccount cosmosAccount = CloudStorageAccount.parse( String.format( COSMOS_CONNECTION_TEMPLATE, configuration.getAccountName(), configuration.getAccountKey(), endpoint)); tableClient = cosmosAccount.createCloudTableClient(); // Create the tables if the do not exist tableClient.getTableReference(JOB_TABLE).createIfNotExists(); tableClient.getTableReference(JOB_DATA_TABLE).createIfNotExists(); CloudStorageAccount blobAccount = CloudStorageAccount.parse( String.format( BLOB_CONNECTION_TEMPLATE, configuration.getAccountName(), configuration.getBlobKey())); blobClient = blobAccount.createCloudBlobClient(); blobClient.getContainerReference(BLOB_CONTAINER).createIfNotExists(); } catch (StorageException | URISyntaxException | InvalidKeyException e) { throw new MicrosoftStorageException(e); } }
public AzureBlobBackupUploader(CloudBlobContainer container, String blobname) throws StorageException { this.container = container; this.blobname = blobname; container.createIfNotExists(); }
private void create() throws StorageException { this.blobContainer.createIfNotExists(); }
public CloudBlobContainer getCloudBlobContainer(final String containerName) throws StorageException, URISyntaxException { CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName); cloudBlobContainer.createIfNotExists(); return cloudBlobContainer; }
/** * Creates the container if it does not exist. * * @return <code>true</code> if the container did not already exist and was created; otherwise, <code>false</code>. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public boolean createIfNotExists() throws StorageException { return this.createIfNotExists(BlobContainerPublicAccessType.OFF, null /* options */, null /* opContext */); }
/** * Creates the container if it does not exist. * * @return <code>true</code> if the container did not already exist and was created; otherwise, <code>false</code>. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public boolean createIfNotExists() throws StorageException { return this.createIfNotExists(BlobContainerPublicAccessType.OFF, null /* options */, null /* opContext */); }
/** * Creates the container if it does not exist, using the specified request options and operation context. * * @param options * A {@link BlobRequestOptions} object that specifies any additional options for the request. * Specifying <code>null</code> will use the default request options from the associated service client * ({@link CloudBlobClient}). * @param opContext * An {@link OperationContext} object that represents the context for the current operation. This object * is used to track requests to the storage service, and to provide additional runtime information about * the operation. * * @return <code>true</code> if the container did not already exist and was created; otherwise, <code>false</code>. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public boolean createIfNotExists(BlobRequestOptions options, OperationContext opContext) throws StorageException { return this.createIfNotExists(BlobContainerPublicAccessType.OFF, options, opContext); }
@Override public CompletableFuture<Void> createLeaseStoreIfNotExists() { CompletableFuture<Void> future = null; try { // returns true if the container was created, false if it already existed -- we don't care this.eventHubContainer.createIfNotExists(this.leaseOperationOptions, null); TRACE_LOGGER.info(this.hostContext.withHost("Created lease store OK or it already existed")); future = CompletableFuture.completedFuture(null); } catch (StorageException e) { future = new CompletableFuture<Void>(); future.completeExceptionally(LoggingUtils.wrapException(e, EventProcessorHostActionStrings.CREATING_LEASE_STORE)); TRACE_LOGGER.error(this.hostContext.withHost("Failure while creating lease store"), e); } return future; }
CloudStorageAccount account = new CloudStorageAccount(st, true); CloudBlobClient blobClient = account.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference(uid); container.createIfNotExists(); CloudBlockBlob blob = container.getBlockBlobReference("filename"); blob.uploadFromStream(new FileInputStream(mFilePath));
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(); }
public static void setUp() throws URISyntaxException, InvalidKeyException, StorageException, IOException { registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString); String uuid = UUID.randomUUID().toString(); deviceId = deviceId.concat("-" + uuid); CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageAccountConnectionString); blobClient = storageAccount.createCloudBlobClient(); // Creating the export storage container and getting its URI String exportContainerName = "exportcontainersample-" + uuid; exportContainer = blobClient.getContainerReference(exportContainerName); exportContainer.createIfNotExists(); // Creating the import storage container and getting its URI String importContainerName = "importcontainersample-" + uuid; importContainer = blobClient.getContainerReference(importContainerName); importContainer.createIfNotExists(); }
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; }
public static CloudBlobDirectory cloudBlobDirectoryFrom(String connection, String containerName, String dir) throws InvalidKeyException, URISyntaxException, StorageException { CloudStorageAccount cloud = CloudStorageAccount.parse(connection); CloudBlobContainer container = cloud.createCloudBlobClient().getContainerReference(containerName); container.createIfNotExists(); return container.getDirectoryReference(dir); }
public static CloudBlobDirectory cloudBlobDirectoryFrom(String connection, String containerName, String dir) throws InvalidKeyException, URISyntaxException, StorageException { CloudStorageAccount cloud = CloudStorageAccount.parse(connection); CloudBlobContainer container = cloud.createCloudBlobClient().getContainerReference(containerName); container.createIfNotExists(); return container.getDirectoryReference(dir); }
public CloudBlobContainer makeObject() throws URISyntaxException, StorageException { SDFSLogger.getLog().info("pool size is " + this.passiveObjects.size()); CloudBlobClient serviceClient = account.createCloudBlobClient(); serviceClient = account.createCloudBlobClient(); serviceClient.getDefaultRequestOptions().setConcurrentRequestCount( Main.dseIOThreads * 2); serviceClient.getDefaultRequestOptions().setTimeoutIntervalInMs( 10 * 1000); serviceClient.getDefaultRequestOptions().setRetryPolicyFactory( new RetryExponentialRetry(500, 5)); CloudBlobContainer container = serviceClient .getContainerReference(this.bucket); container.createIfNotExists(); return container; }
/** * Try to create a container after it is created * * @throws StorageException * @throws URISyntaxException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerCreateIfNotExists() throws StorageException { assertTrue(this.container.createIfNotExists()); assertTrue(this.container.exists()); assertFalse(this.container.createIfNotExists()); }
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; }
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; }