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


Java CloudBlockBlob.uploadText方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:23,代码来源:CloudFileTests.java

示例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();
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:25,代码来源:ClientLoggingBasics.java

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

示例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();
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:62,代码来源:FileSasTests.java


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