本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlobContainer.uploadPermissions方法的典型用法代码示例。如果您正苦于以下问题:Java CloudBlobContainer.uploadPermissions方法的具体用法?Java CloudBlobContainer.uploadPermissions怎么用?Java CloudBlobContainer.uploadPermissions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.microsoft.azure.storage.blob.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.uploadPermissions方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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;
}
示例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: 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;
}
}
示例6: 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;
}
示例7: setPublicAccess
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public void setPublicAccess(String containerName) throws URISyntaxException, StorageException, InvalidKeyException {
CloudBlobClient cloudBlobClient = connection.getCloudStorageAccount().createCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName);
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
cloudBlobContainer.uploadPermissions(containerPermissions);
}
示例8: setPublicPermissionOnContainer
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public void setPublicPermissionOnContainer(String resourceGroup, String storageName, String containerName) {
LOGGER.debug("set public permission on container: RG={}, storageName={}, containerName={}", resourceGroup, storageName, containerName);
CloudBlobContainer container = getBlobContainer(resourceGroup, storageName, containerName);
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
try {
container.uploadPermissions(containerPermissions);
} catch (StorageException e) {
throw new CloudConnectorException("can't set public permission on container, storage service error occurred", e);
}
}
示例9: generateSAS
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
private static String generateSAS(CloudBlobContainer container,
boolean readonly) throws Exception {
// Create a container if it does not exist.
container.createIfNotExists();
// Create a new shared access policy.
SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy();
// Create a UTC Gregorian calendar value.
GregorianCalendar calendar = new GregorianCalendar(
TimeZone.getTimeZone("UTC"));
// Specify the current time as the start time for the shared access
// signature.
//
calendar.setTime(new Date());
sasPolicy.setSharedAccessStartTime(calendar.getTime());
// Use the start time delta one hour as the end time for the shared
// access signature.
calendar.add(Calendar.HOUR, 10);
sasPolicy.setSharedAccessExpiryTime(calendar.getTime());
if (readonly) {
// Set READ permissions
sasPolicy.setPermissions(EnumSet.of(
SharedAccessBlobPermissions.READ,
SharedAccessBlobPermissions.LIST));
} else {
// Set READ and WRITE permissions.
//
sasPolicy.setPermissions(EnumSet.of(
SharedAccessBlobPermissions.READ,
SharedAccessBlobPermissions.WRITE,
SharedAccessBlobPermissions.LIST));
}
// Create the container permissions.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
// Turn public access to the container off.
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.OFF);
container.uploadPermissions(containerPermissions);
// Create a shared access signature for the container.
String sas = container.generateSharedAccessSignature(sasPolicy, null);
// HACK: when the just generated SAS is used straight away, we get an
// authorization error intermittently. Sleeping for 1.5 seconds fixes that
// on my box.
Thread.sleep(1500);
// Return to caller with the shared access signature.
return sas;
}
示例10: primePublicContainer
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static void primePublicContainer(CloudBlobClient blobClient,
String accountName, String containerName, 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(containerName);
container.createIfNotExists();
// Create a new shared access policy.
SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy();
// Set READ and WRITE permissions.
//
sasPolicy.setPermissions(EnumSet.of(
SharedAccessBlobPermissions.READ,
SharedAccessBlobPermissions.WRITE,
SharedAccessBlobPermissions.LIST,
SharedAccessBlobPermissions.DELETE));
// Create the container permissions.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
// Turn public access to the container off.
containerPermissions
.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
// Set the policy using the values set above.
containerPermissions.getSharedAccessPolicies().put("testwasbpolicy",
sasPolicy);
container.uploadPermissions(containerPermissions);
// Create a blob output stream.
CloudBlockBlob blob = container.getBlockBlobReference(blobName);
BlobOutputStream outputStream = blob.openOutputStream();
outputStream.write(new byte[fileSize]);
outputStream.close();
}
示例11: setup
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@PostConfig
@PostCreated
@PostRecovery
public void setup()
{
_serviceBaseURL = _properties.get(SERVICEBASEURL_PROPERTYNAME);
_containerName = _properties.get(CONTAINERNAME_PROPERTYNAME);
_storageConnection = _properties.get(STORAGECONNECTION_PROPERTYNAME);
_accountName = _properties.get(ACCOUNTNAME_PROPERTYNAME);
_accountKey = _properties.get(ACCOUNTKEY_PROPERTYNAME);
_containerSAS = _properties.get(CONTAINERSAS_PROPERTYNAME);
if ((_containerSAS == null) || "".equals(_containerSAS.trim()))
{
String storageConnection = null;
if ((_storageConnection != null) && (! "".equals(_storageConnection.trim())))
storageConnection = _storageConnection;
else if ((_accountName != null) && (! "".equals(_accountName.trim())) && (_accountKey != null) && (! "".equals(_accountKey.trim())))
storageConnection = "DefaultEndpointsProtocol=https;AccountName=" + _accountName + ";AccountKey=" + _accountKey;
if (storageConnection != null)
{
try
{
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnection);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.getContainerReference(_containerName);
blobContainer.createIfNotExists();
SharedAccessBlobPolicy blobPolicy = new SharedAccessBlobPolicy();
GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
calendar.setTime(new Date());
blobPolicy.setSharedAccessStartTime(calendar.getTime());
calendar.add(Calendar.HOUR, 6);
blobPolicy.setSharedAccessExpiryTime(calendar.getTime());
blobPolicy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE));
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.OFF);
containerPermissions.getSharedAccessPolicies().put("accesspolicy", blobPolicy);
blobContainer.uploadPermissions(containerPermissions);
_containerSAS = blobContainer.generateSharedAccessSignature(blobPolicy, null);
}
catch (Throwable throwable)
{
logger.log(Level.WARNING, "Problems with Azure blob store SAS", throwable);
}
}
}
}