本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlockBlob.uploadText方法的典型用法代码示例。如果您正苦于以下问题:Java CloudBlockBlob.uploadText方法的具体用法?Java CloudBlockBlob.uploadText怎么用?Java CloudBlockBlob.uploadText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.microsoft.azure.storage.blob.CloudBlockBlob
的用法示例。
在下文中一共展示了CloudBlockBlob.uploadText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCopyBlockBlobSas
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的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();
}
}
示例2: EnablePerRequestLogging
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的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();
}
示例3: uploadText
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
/**
* 上传文件
* @param container 容器
* @param blobName 上传到容器中的Blob名
* @param text 文本内容
* @return 是否上传成功
*/
public static boolean uploadText(CloudBlobContainer container, String blobName, String text) {
DebugLog.d(TAG, "uploadText() blobName = " + blobName + " , text = " + text);
try {
CloudBlockBlob blob = container.getBlockBlobReference(blobName);
blob.uploadText(text);
return true;
} catch (Exception e) {
DebugLog.e(TAG, "uploadText()", e);
return false;
}
}
示例4: testFileCopyFromBlobWithSasAndSnapshot
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
@Test
public void testFileCopyFromBlobWithSasAndSnapshot()
throws URISyntaxException, StorageException, InterruptedException, IOException, InvalidKeyException {
String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob");
CloudBlobContainer container = TestHelper.createCloudBlobClient().getContainerReference(BlobTestHelper.generateRandomContainerName());
container.createIfNotExists();
CloudBlockBlob source = container.getBlockBlobReference(blobName);
String data = "String data";
source.uploadText(data, Constants.UTF8_CHARSET, null, null, null);
byte[] buffer = BlobTestHelper.getRandomBuffer(512);
ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
source.upload(stream, buffer.length);
source.getMetadata().put("Test", "value");
source.uploadMetadata();
SharedAccessFilePolicy policy = createSharedAccessPolicy(
EnumSet.of(SharedAccessFilePermissions.READ, SharedAccessFilePermissions.WRITE,
SharedAccessFilePermissions.LIST, SharedAccessFilePermissions.DELETE), 5000);
CloudFile copy = this.share.getRootDirectoryReference().getFileReference("copy");
String sasToken = copy.generateSharedAccessSignature(policy, null);
CloudFile copySas = new CloudFile(new URI(copy.getUri().toString() + "?" + sasToken));
// Generate account SAS for the source
// Cannot generate a SAS directly on a snapshot and the SAS for the destination is only for the destination
SharedAccessAccountPolicy accountPolicy = new SharedAccessAccountPolicy();
accountPolicy.setPermissions(EnumSet.of(SharedAccessAccountPermissions.READ, SharedAccessAccountPermissions.WRITE));
accountPolicy.setServices(EnumSet.of(SharedAccessAccountService.BLOB));
accountPolicy.setResourceTypes(EnumSet.of(SharedAccessAccountResourceType.OBJECT, SharedAccessAccountResourceType.CONTAINER));
accountPolicy.setSharedAccessExpiryTime(policy.getSharedAccessExpiryTime());
final CloudBlobClient sasClient = TestHelper.createCloudBlobClient(accountPolicy, false);
CloudBlockBlob snapshot = (CloudBlockBlob) source.createSnapshot();
CloudBlockBlob sasBlob = (CloudBlockBlob) sasClient.getContainerReference(container.getName())
.getBlobReferenceFromServer(snapshot.getName(), snapshot.getSnapshotID(), null, null, null);
sasBlob.exists();
String copyId = copySas.startCopy(BlobTestHelper.defiddler(sasBlob));
FileTestHelper.waitForCopy(copySas);
copySas.downloadAttributes();
FileProperties prop1 = copySas.getProperties();
BlobProperties prop2 = sasBlob.getProperties();
assertEquals(prop1.getCacheControl(), prop2.getCacheControl());
assertEquals(prop1.getContentEncoding(), prop2.getContentEncoding());
assertEquals(prop1.getContentDisposition(),
prop2.getContentDisposition());
assertEquals(prop1.getContentLanguage(), prop2.getContentLanguage());
assertEquals(prop1.getContentMD5(), prop2.getContentMD5());
assertEquals(prop1.getContentType(), prop2.getContentType());
assertEquals("value", copySas.getMetadata().get("Test"));
assertEquals(copyId, copySas.getCopyState().getCopyId());
snapshot.delete();
source.delete();
copySas.delete();
container.delete();
}