本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlobContainer.getBlockBlobReference方法的典型用法代码示例。如果您正苦于以下问题:Java CloudBlobContainer.getBlockBlobReference方法的具体用法?Java CloudBlobContainer.getBlockBlobReference怎么用?Java CloudBlobContainer.getBlockBlobReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.microsoft.azure.storage.blob.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.getBlockBlobReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadToAzureStorage
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的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: moveBlob
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的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);
}
}
示例3: getImageAsArray
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的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;
}
示例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;
}
示例5: getImageAsArray
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的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;
}
示例6: 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;
}
示例7: 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;
}
示例8: testCopyBlockBlobSas
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
@Category(SlowTests.class)
public void testCopyBlockBlobSas() throws Exception {
// Create source on server.
final CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
try {
container.create();
final CloudBlockBlob source = container.getBlockBlobReference("source");
source.getMetadata().put("Test", "value");
final String data = "String data";
source.uploadText(data, Constants.UTF8_CHARSET, null, null, null);
final CloudFile destination = doCloudBlobCopy(source, data.length());
final String copyData = destination.downloadText(Constants.UTF8_CHARSET, null, null, null);
assertEquals(data, copyData);
}
finally {
container.deleteIfExists();
}
}
示例9: EnablePerRequestLogging
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static void EnablePerRequestLogging(CloudBlobContainer container) throws StorageException, URISyntaxException, IOException {
System.out.println("Enable logging per selected requests");
// Set logging to false by default and pass in an operation context to log only specific APIs
OperationContext.setLoggingEnabledByDefault(false);
// Upload a blob passing in the operation context
// Get a reference to a blob in the container
// This operation will not be logged since it does not make a service request.
CloudBlockBlob blob = container.getBlockBlobReference("blob");
OperationContext operationContext = new OperationContext();
operationContext.setLoggingEnabled(true);
// Upload text to the blob passing in the operation context so the request is logged.
// This operation contacts the Azure Storage Service and will be logged
// since it is passing in an operation context that enables logging.
blob.uploadText("Hello, World", null, null, null, operationContext);
// Delete the container if it exists.
// This operation will not be logged since logging has been disabled
// by default and no operation context is being passed in.
container.deleteIfExists();
}
示例10: 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);
}
示例11: regularUpload
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
private boolean regularUpload(CloudBlobContainer container, String fileName, PluggableMessage pluggableMessage,
Map<String, String> customMetadata, long fileSize) throws UnableToProduceException {
boolean status = false;
CloudBlockBlob singleBlob;
String containerName = container.getName();
try {
if (container.exists()) {
log.info(LOGGER_KEY + "Container exists: " + containerName);
singleBlob = container.getBlockBlobReference(fileName);
log.info(LOGGER_KEY + "User metadata being applied ..." + customMetadata.size() + " key(s)");
singleBlob.setMetadata((HashMap<String, String>) customMetadata);
log.info(LOGGER_KEY + "Initiating blob upload with regular mode");
singleBlob.upload(FileUtils.openInputStream(pluggableMessage.getData().toFile()), fileSize);
if (singleBlob.exists())
log.info(LOGGER_KEY + "Azure Blob upload finished successfully.");
}
} catch (URISyntaxException urie) {
log.error(LOGGER_KEY + "Azure Resource URI constructed based on the containerName is invalid. "
+ urie.getMessage());
throw new UnableToProduceException(urie.getMessage(), urie);
} catch (StorageException se) {
log.error(LOGGER_KEY + "Azure Storage Service Error occurred. " + se.getMessage());
throw new UnableToProduceException(se.getMessage(), se);
} catch (IOException ioe) {
log.error(LOGGER_KEY + "Azure Storage I/O exception occurred. " + ioe.getMessage());
throw new UnableToProduceException(ioe.getMessage(), ioe);
} finally {
status = true;
}
return status;
}
示例12: blobExists
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Override
public boolean blobExists(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
// Container name must be lower case.
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
if (blobContainer.exists()) {
CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blob);
return SocketAccess.doPrivilegedException(azureBlob::exists);
}
return false;
}
示例13: deleteBlob
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Override
public void deleteBlob(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
logger.trace("delete blob for container [{}], blob [{}]", container, blob);
// Container name must be lower case.
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
if (blobContainer.exists()) {
logger.trace("container [{}]: blob [{}] found. removing.", container, blob);
CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blob);
SocketAccess.doPrivilegedVoidException(azureBlob::delete);
}
}
示例14: 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();
}
示例15: deleteBlob
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static void deleteBlob(final CloudStorageAccount storageAccount, final String containerName,
final String blobName) throws Exception {
final CloudBlobContainer blobContainer = getBlobContainer(storageAccount, containerName);
if (blobContainer.exists()) {
final CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobName);
blob.deleteIfExists();
}
}