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


Java CloudBlobClient类代码示例

本文整理汇总了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;
}
 
开发者ID:Microsoft,项目名称:movie-db-java-on-azure,代码行数:32,代码来源:AzureStorageUploader.java

示例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);
            }
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:AzureStorageServiceImpl.java

示例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);
}
 
开发者ID:Microsoft,项目名称:azure-maven-plugins,代码行数:21,代码来源:MSDeployArtifactHandlerImplTest.java

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

示例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());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:AzureStorageServiceImpl.java

示例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();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:AzureStorageServiceImpl.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:AzureStorageServiceImpl.java

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

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

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

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

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

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

示例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;
}
 
开发者ID:mesosphere,项目名称:dcos-cassandra-service,代码行数:22,代码来源:AzureStorageDriver.java

示例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;
	}
}
 
开发者ID:leleliu008,项目名称:Newton_for_Android_AS,代码行数:22,代码来源:AzureStorage.java


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