String storageConnectionString = String.format(AzureStorageUtils.FORMAT_BASE_URI, accountName); StorageCredentials creds = new StorageCredentialsSharedAccessSignature(sasToken); cloudBlobClient = new CloudBlobClient(new URI(storageConnectionString), creds); } else { String blobConnString = String.format(AzureStorageUtils.FORMAT_BLOB_CONNECTION_STRING, accountName, accountKey);
URI BlobEndPoint = new URI("http://127.0.0.1:10000/devstoreaccount1"); CloudBlobClient bClient = new CloudBlobClient(BlobEndPoint, new StorageCredentialsAccountAndKey(AccountName, AccountSecurityKey));
@Override public void createBlobClient(URI baseUri, StorageCredentials credentials) { serviceClient = new CloudBlobClient(baseUri, credentials); updateRetryPolicy(); updateTimeoutInMs(); }
public class SASmeta { public static void main(String[] args) throws URISyntaxException, FileNotFoundException, StorageException, IOException { URI baseuri = new URI("http://grassy.blob.core.windows.net"); CloudBlobClient blobclient = new CloudBlobClient(baseuri); MyUploadBlob("container1","sr=c&sv=2012-02-12&sig=b%2BK%2FmX8r7dLCVxs5PSPmmji1L6kSxNupp9SKF7yj27w%3D&si=r",blobclient); } public static void MyUploadBlob(String containerName, String containerSAS, CloudBlobClient blobClient) throws URISyntaxException, StorageException, FileNotFoundException, IOException { String blobName = "image1.jpg"; String localFileName = "c:\\myimages\\image1.jpg"; URI uri = new URI(blobClient.getEndpoint().toString() + "/" + containerName + "/" + blobName + "?" + containerSAS); CloudBlockBlob sasBlob = new CloudBlockBlob(uri, blobClient); HashMap<String, String> user = new HashMap<String, String>(); user.put("firstname", "Joe"); user.put("lastname", "Smith" ); user.put("age", "28"); user.put("presenter", "no"); sasBlob.setMetadata(user); File fileReference = new File(localFileName); sasBlob.upload(new FileInputStream(fileReference), fileReference.length()); System.out.println("The blob: " + blobName + " has been uploaded to:"); System.out.println(uri); } }
/** * Creates a new Blob service client. * * @return A {@link CloudBlobClient} that represents the cloud Blob client. * */ public CloudBlobClient createCloudBlobClient() { if (this.getBlobStorageUri() == null) { throw new IllegalArgumentException(SR.BLOB_ENDPOINT_NOT_CONFIGURED); } if (this.credentials == null) { throw new IllegalArgumentException(SR.MISSING_CREDENTIALS); } return new CloudBlobClient(this.getBlobStorageUri(), this.getCredentials()); }
/** * Creates a new Blob service client. * * @return A {@link CloudBlobClient} that represents the cloud Blob client. * */ public CloudBlobClient createCloudBlobClient() { if (this.getBlobStorageUri() == null) { throw new IllegalArgumentException(SR.BLOB_ENDPOINT_NOT_CONFIGURED); } if (this.credentials == null) { throw new IllegalArgumentException(SR.MISSING_CREDENTIALS); } return new CloudBlobClient(this.getBlobStorageUri(), this.getCredentials()); }
/** * Download file from Azure and save to target path specified. Return true if download succeeds * @param filePathName * @return */ private static Boolean downloadFromAzure(@NotNull Path filePathName) { boolean result = true; try { URI cloudBlobUri = new URI(AZURE_BLOB_URI); CloudBlobClient serviceClient = new CloudBlobClient(cloudBlobUri); CloudBlobContainer container = serviceClient.getContainerReference("libcontainer1"); CloudBlockBlob blob = container.getBlockBlobReference(filePathName.getFileName().toString()); File downloadingFile = filePathName.toFile(); blob.downloadToFile(downloadingFile.getAbsolutePath()); } catch (Exception e) { result = false; log.warning("Fail to download file from Azure: " + e.getMessage()); } return result; }
CloudBlobClient blobclient = new CloudBlobClient(baseuri); MyDownloadBlob("container1", "sr=c&sv=2012-02-12&sig=nnPn5P5nnPPnn5Pnn5PPnPPPnPPP5PPPPPP%5PPnn5PPn%55&si=heath",
CloudBlobClient blobclient = new CloudBlobClient(baseuri); MyUploadBlob("container1", "sr=c&sv=2012-02-12&sig=nnPn5P5nnPPnn5Pnn5PPnPPPnPPP5PPPPPP%5PPnn5PPn%55&si=heath",
/** * Initializes a new instance of the <code>CloudAnalyticsClient</code> class using the specified blob and table * service endpoints and account credentials. * * @param blobStorageUri * A {@link StorageUri} object containing the Blob service endpoint to use to create the client. * @param tableStorageUri * A {@link StorageUri} object containing the Table service endpoint to use to create the client. * @param credentials * A {@link StorageCredentials} object. */ public CloudAnalyticsClient(StorageUri blobStorageUri, StorageUri tableStorageUri, StorageCredentials credentials) { Utility.assertNotNull("blobStorageUri", blobStorageUri); Utility.assertNotNull("tableStorageUri", tableStorageUri); this.blobClient = new CloudBlobClient(blobStorageUri, credentials); this.tableClient = new CloudTableClient(tableStorageUri, credentials); }
/** * Initializes a new instance of the <code>CloudAnalyticsClient</code> class using the specified blob and table * service endpoints and account credentials. * * @param blobStorageUri * A {@link StorageUri} object containing the Blob service endpoint to use to create the client. * @param tableStorageUri * A {@link StorageUri} object containing the Table service endpoint to use to create the client. * @param credentials * A {@link StorageCredentials} object. */ public CloudAnalyticsClient(StorageUri blobStorageUri, StorageUri tableStorageUri, StorageCredentials credentials) { Utility.assertNotNull("blobStorageUri", blobStorageUri); Utility.assertNotNull("tableStorageUri", tableStorageUri); this.blobClient = new CloudBlobClient(blobStorageUri, credentials); this.tableClient = new CloudTableClient(tableStorageUri, credentials); }
final CloudBlobClient client = new CloudBlobClient(uri, credentials); client.setDirectoryDelimiter(String.valueOf(Path.DELIMITER)); final BlobRequestOptions options = new BlobRequestOptions();
this.blobServiceClient = new CloudBlobClient(PathUtility.getServiceClientBaseAddress( this.getStorageUri(), usePathStyleUris), credentials != null ? credentials : parsedCredentials); this.name = PathUtility.getBlobNameFromURI(this.storageUri.getPrimaryUri(), usePathStyleUris);
this.blobServiceClient = new CloudBlobClient(PathUtility.getServiceClientBaseAddress( this.getStorageUri(), usePathStyleUris), credentials != null ? credentials : parsedCredentials); this.name = PathUtility.getContainerNameFromUri(this.storageUri.getPrimaryUri(), usePathStyleUris);
this.blobServiceClient = new CloudBlobClient(PathUtility.getServiceClientBaseAddress( this.getStorageUri(), usePathStyleUris), credentials != null ? credentials : parsedCredentials); this.name = PathUtility.getContainerNameFromUri(this.storageUri.getPrimaryUri(), usePathStyleUris);
this.blobServiceClient = new CloudBlobClient(PathUtility.getServiceClientBaseAddress( this.getStorageUri(), usePathStyleUris), credentials != null ? credentials : parsedCredentials); this.name = PathUtility.getBlobNameFromURI(this.storageUri.getPrimaryUri(), usePathStyleUris);
@Test @Category(SlowTests.class) public void testBlobSaS() throws InvalidKeyException, IllegalArgumentException, StorageException, URISyntaxException, InterruptedException { SharedAccessBlobPolicy sp = createSharedAccessPolicy( EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.LIST), 3600); BlobContainerPermissions perms = new BlobContainerPermissions(); perms.getSharedAccessPolicies().put("readperm", sp); this.container.uploadPermissions(perms); Thread.sleep(30000); CloudBlockBlob sasBlob = new CloudBlockBlob(new URI(this.blob.getUri().toString() + "?" + this.blob.generateSharedAccessSignature(null, "readperm"))); sasBlob.download(new ByteArrayOutputStream()); // do not give the client and check that the new blob's client has the correct perms CloudBlob blobFromUri = new CloudBlockBlob(PathUtility.addToQuery(this.blob.getStorageUri(), this.blob.generateSharedAccessSignature(null, "readperm"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), blobFromUri.getServiceClient() .getCredentials().getClass().toString()); // create credentials from sas StorageCredentials creds = new StorageCredentialsSharedAccessSignature( this.blob.generateSharedAccessSignature(null, "readperm")); CloudBlobClient bClient = new CloudBlobClient(sasBlob.getServiceClient().getStorageUri(), creds); CloudBlockBlob blobFromClient = bClient.getContainerReference(this.blob.getContainer().getName()) .getBlockBlobReference(this.blob.getName()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), blobFromClient.getServiceClient() .getCredentials().getClass().toString()); assertEquals(bClient, blobFromClient.getServiceClient()); }
CloudBlobClient bClient = new CloudBlobClient(this.container.getServiceClient().getStorageUri(), creds);
@Test public void testLocationModeWithMissingUri() throws URISyntaxException, StorageException { CloudBlobClient client = TestHelper.createCloudBlobClient(); CloudBlobClient primaryOnlyClient = new CloudBlobClient(client.getEndpoint(), client.getCredentials()); CloudBlobContainer container = primaryOnlyClient.getContainerReference("nonexistingcontainer");
new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + BLOB_SERVICE + ENDPOINT_SUFFIX)); CloudBlobClient client = new CloudBlobClient(endpoint, blobClient.getCredentials()); assertEquals(endpoint, client.getStorageUri()); assertEquals(endpoint.getPrimaryUri(), client.getEndpoint());