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


Java CloudBlockBlob.upload方法代码示例

本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlockBlob.upload方法的典型用法代码示例。如果您正苦于以下问题:Java CloudBlockBlob.upload方法的具体用法?Java CloudBlockBlob.upload怎么用?Java CloudBlockBlob.upload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.microsoft.azure.storage.blob.CloudBlockBlob的用法示例。


在下文中一共展示了CloudBlockBlob.upload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadToAzureStorage

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的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: write

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
@Override
protected void write(final List<PingData> list, final String clustername) {
    if (list == null || clustername == null) {
        return;
    }

    String filename = addressToFilename(clustername, local_addr);
    ByteArrayOutputStream out = new ByteArrayOutputStream(STREAM_BUFFER_SIZE);

    try {
        write(list, out);
        byte[] data = out.toByteArray();

        // Upload the file
        CloudBlockBlob blob = containerReference.getBlockBlobReference(filename);
        blob.upload(new ByteArrayInputStream(data), data.length);

    } catch (Exception ex) {
        log.error("Error marshalling and uploading ping data.", ex);
    }

}
 
开发者ID:jgroups-extras,项目名称:jgroups-azure,代码行数:23,代码来源:AZURE_PING.java

示例3: testUploadBlob

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
public void testUploadBlob() {
    try {
        // Define the path to a local file.
        final String filePath = "C:\\myimages\\myimage.jpg";

        // Create or overwrite the "myimage.jpg" blob with contents from a
        // local file.
        // container.getDirectoryReference("").
        CloudBlockBlob blob = container.getBlockBlobReference("myimage.jpg");
        File source = new File(filePath);
        blob.upload(new FileInputStream(source), source.length());
    } catch (Exception e) {
        // Output the stack trace.
        e.printStackTrace();
    }
}
 
开发者ID:dzh,项目名称:jframe,代码行数:17,代码来源:TestBlobService.java

示例4: uploadImage

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的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);

}
 
开发者ID:BANKEX,项目名称:smart-asset-iot-android-demo,代码行数:11,代码来源:ImageManager.java

示例5: regularUpload

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的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;
}
 
开发者ID:cmanda,项目名称:axway-b2b-plugins,代码行数:35,代码来源:AzureBlobPluggableTransport.java

示例6: uploadFileAsBlob

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的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();
}
 
开发者ID:Microsoft,项目名称:azure-maven-plugins,代码行数:10,代码来源:AzureStorageHelper.java

示例7: showBlob

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
@RequestMapping(value = "/blob", method = RequestMethod.GET)
public @ResponseBody void showBlob(HttpServletResponse response)
{
	try
	{
		LOG.info("showBlob start");
		if (account == null)
		{
			account = factory.createAccountByServiceInstanceName("mystorage");
		}

		URL u = new URL(IMAGE_PATH);
		InputStream is = u.openStream();
		response.setContentType(MediaType.IMAGE_JPEG_VALUE);
		int imageSize = IOUtils.copy(is, response.getOutputStream());

		LOG.debug("Connecting to storage account...");
		CloudBlobClient serviceClient = account.createCloudBlobClient();

		// Container name must be lower case.
		CloudBlobContainer container = serviceClient.getContainerReference("myimages");
		container.createIfNotExists();

		// Upload an image file.
		LOG.debug("Uploading image...");
		CloudBlockBlob blob = container.getBlockBlobReference("image1.jpg");
		blob.upload(new URL(IMAGE_PATH).openStream(), imageSize);
		LOG.debug("Uploading image complete");

	} catch (Exception e)
	{
		LOG.error("Error processing request ", e);
	}
}
 
开发者ID:pivotal-partner-solution-architecture,项目名称:azure-service-broker-client,代码行数:35,代码来源:StorageRestController.java

示例8: testConnectUsingSASReadonly

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
@Test
public void testConnectUsingSASReadonly() throws Exception {
  // Create the test account with SAS credentials.
  testAccount = AzureBlobStorageTestAccount.create("", EnumSet.of(
      CreateOptions.UseSas, CreateOptions.CreateContainer,
      CreateOptions.Readonly));
  assumeNotNull(testAccount);

  // Create a blob in there
  final String blobKey = "blobForReadonly";
  CloudBlobContainer container = testAccount.getRealContainer();
  CloudBlockBlob blob = container.getBlockBlobReference(blobKey);
  ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[] { 1,
      2, 3 });
  blob.upload(inputStream, 3);
  inputStream.close();

  // Make sure we can read it from the file system
  Path filePath = new Path("/" + blobKey);
  FileSystem fs = testAccount.getFileSystem();
  assertTrue(fs.exists(filePath));
  byte[] obtained = new byte[3];
  DataInputStream obtainedInputStream = fs.open(filePath);
  obtainedInputStream.readFully(obtained);
  obtainedInputStream.close();
  assertEquals(3, obtained[2]);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestWasbUriAndConfiguration.java

示例9: store

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
/**
 * Uploads a file to Azure.
 * 
 * @throws StorageException
 * @throws URISyntaxException
 */
@Override
public void store(File file) throws IOException, GeneralSecurityException,
		StorageException, URISyntaxException {
	CloudBlockBlob blob = container.getBlockBlobReference(file.getName());
	blob.upload(new FileInputStream(file), file.length());
	LogUtils.debug(LOG_TAG, "File " + file.getName() + " was uploaded.");
}
 
开发者ID:darshanmaiya,项目名称:MCSFS,代码行数:14,代码来源:AzureStore.java

示例10: upload

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
public void upload(final String containerName, final String blobName, final InputStream sourceStream, final long length)
        throws StorageException, IOException, URISyntaxException, InvalidKeyException {
    CloudBlobClient cloudBlobClient = connection.getCloudStorageAccount().createCloudBlobClient();
    CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName);
    CloudBlockBlob blob = cloudBlobContainer.getBlockBlobReference(blobName);
    blob.upload(sourceStream, length);
}
 
开发者ID:Talend,项目名称:components,代码行数:8,代码来源:AzureStorageBlobService.java

示例11: CreateLogs

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
public static List<String> CreateLogs(CloudBlobContainer container, StorageService service, int count,
        Calendar start, Granularity granularity) throws URISyntaxException, StorageException, IOException {
    String name;
    List<String> blobs = new ArrayList<String>();
    DateFormat hourFormat = new SimpleDateFormat("yyyy/MM/dd/HH");
    hourFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

    CloudBlockBlob blockBlob;
    name = service.toString().toLowerCase(Locale.US) + "/" + hourFormat.format(start.getTime()) + "00/000001.log";
    blockBlob = container.getBlockBlobReference(name);
    blockBlob.upload(getRandomDataStream(1), 1, null, null, null);
    blobs.add(name);

    for (int i = 1; i < count; i++) {
        if (granularity.equals(Granularity.HOUR)) {
            start.add(GregorianCalendar.HOUR_OF_DAY, 1);
        }
        else if (granularity.equals(Granularity.DAY)) {
            start.add(GregorianCalendar.DAY_OF_MONTH, 1);
        }
        else if (granularity.equals(Granularity.MONTH)) {
            start.add(GregorianCalendar.MONTH, 1);
        }
        else {
            throw new IllegalArgumentException(String.format(Locale.US,
                    "CreateLogs granularity of '{0}' is invalid.", granularity));
        }

        name = service.toString().toLowerCase(Locale.US) + "/" + hourFormat.format(start.getTime())
                + "00/000001.log";
        blockBlob = container.getBlockBlobReference(name);
        blockBlob.upload(getRandomDataStream(1), 1, null, null, null);
        blobs.add(name);
    }

    return blobs;
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:38,代码来源:AnalyticsTestHelper.java

示例12: CreateLogs

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
public static List<String> CreateLogs(CloudBlobContainer container, StorageService service, int count,
        Calendar start, Granularity granularity) throws URISyntaxException, StorageException, IOException {
    String name;
    List<String> blobs = new ArrayList<String>();
    DateFormat hourFormat = new SimpleDateFormat("yyyy/MM/dd/HH");
    hourFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

    CloudBlockBlob blockBlob;
    name = service.toString().toLowerCase(Locale.US) + "/" + hourFormat.format(start.getTime()) + "00/000001.log";
    blockBlob = container.getBlockBlobReference(name);
    blockBlob.upload(getRandomDataStream(1), 1, null, null, null);
    blobs.add(name);

    for (int i = 1; i < count; i++) {
        if (granularity.equals(Granularity.HOUR)) {
            start.add(GregorianCalendar.HOUR_OF_DAY, 1);
        }
        else if (granularity.equals(Granularity.DAY)) {
            start.add(GregorianCalendar.DAY_OF_MONTH, 1);
        }
        else if (granularity.equals(Granularity.MONTH)) {
            start.add(GregorianCalendar.MONTH, 1);
        }
        else {
            throw new IllegalArgumentException(String.format(Locale.US,
                    "CreateLogs granularity of '{0}' is invalid.", granularity));
        }

        name = service.toString().toLowerCase(Locale.US) + "/" + hourFormat.format(start.getTime())
                + "00/000001.log";
        blockBlob = container.getBlockBlobReference(name);
        blockBlob.upload(getRandomDataStream(1), 1, null, null, null);
        blobs.add(name);
        //System.out.println("BLOB ADDED: " + name);
    }

    return blobs;
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:39,代码来源:AnalyticsTestHelper.java

示例13: storeBackup

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
@Override
public void storeBackup(File zipfile) throws BackupUploadException {
  try {
    final CloudBlockBlob blob = container.getBlockBlobReference(blobname);
    blob.upload(new FileInputStream(zipfile), zipfile.length());
  } catch (URISyntaxException | StorageException | IOException e) {
    throw new BackupUploadException(e);
  }
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:10,代码来源:AzureBlobBackupUploader.java

示例14: showCopy

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
@RequestMapping(value = "/blob2", method = RequestMethod.GET)
public @ResponseBody void showCopy(HttpServletResponse response)
{
	try
	{
		LOG.info("showCopy start");

		CloudStorageAccount account1 = factory.createAccountByServiceInstanceName("mystorage");
		CloudStorageAccount account2 = factory.createAccountByServiceInstanceName("mystorage2");

		URL u = new URL(IMAGE_PATH);
		InputStream is = u.openStream();
		response.setContentType(MediaType.IMAGE_JPEG_VALUE);
		int imageSize = IOUtils.copy(is, response.getOutputStream());

		LOG.debug("Connecting to storage account 1...");
		CloudBlobClient serviceClient1 = account1.createCloudBlobClient();

		// Container name must be lower case.
		CloudBlobContainer container = serviceClient1.getContainerReference("myimages");
		container.createIfNotExists();

		// Upload an image file.
		LOG.debug("Uploading image...");
		CloudBlockBlob blob = container.getBlockBlobReference("image1.jpg");
		blob.upload(new URL(IMAGE_PATH).openStream(), imageSize);
		LOG.debug("Uploading image complete to account 1");

		LOG.debug("Connecting to storage account 2...");
		CloudBlobClient serviceClient2 = account2.createCloudBlobClient();

		// Container name must be lower case.
		container = serviceClient2.getContainerReference("myimages");
		container.createIfNotExists();

		// Upload an image file.
		LOG.debug("Uploading image...");
		blob = container.getBlockBlobReference("image1.jpg");
		blob.upload(new URL(IMAGE_PATH).openStream(), imageSize);
		LOG.debug("Uploading image complete to account 2");
	} catch (Exception e)
	{
		LOG.error("Error processing request ", e);
	}
}
 
开发者ID:pivotal-partner-solution-architecture,项目名称:azure-service-broker-client,代码行数:46,代码来源:StorageRestController.java

示例15: testReadTimeoutIssue

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
public void testReadTimeoutIssue() throws URISyntaxException, StorageException, IOException {
    // part 1
    byte[] buffer = BlobTestHelper.getRandomBuffer(1 * 1024 * 1024);

    // set the maximum execution time
    BlobRequestOptions options = new BlobRequestOptions();
    options.setMaximumExecutionTimeInMs(5000);

    CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference(generateRandomContainerName());

    String blobName = "testBlob";
    final CloudBlockBlob blockBlobRef = container.getBlockBlobReference(blobName);
    blockBlobRef.setStreamWriteSizeInBytes(1 * 1024 * 1024);

    ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
    BlobOutputStream blobOutputStream = null;

    try {
        container.createIfNotExists();
        blobOutputStream = blockBlobRef.openOutputStream(null, options, null);
        try {
            blobOutputStream.write(inputStream, buffer.length);
        } finally {
            blobOutputStream.close();
        }
        assertTrue(blockBlobRef.exists());
    } finally {
        inputStream.close();
        container.deleteIfExists();
    }

    // part 2
    int length2 = 10 * 1024 * 1024;
    byte[] uploadBuffer2 = BlobTestHelper.getRandomBuffer(length2);

    CloudBlobClient blobClient2 = TestHelper.createCloudBlobClient();
    CloudBlobContainer container2 = blobClient2.getContainerReference(generateRandomContainerName());

    String blobName2 = "testBlob";
    final CloudBlockBlob blockBlobRef2 = container2.getBlockBlobReference(blobName2);

    ByteArrayInputStream inputStream2 = new ByteArrayInputStream(uploadBuffer2);

    try {
        container2.createIfNotExists();

        blockBlobRef2.upload(inputStream2, length2);
    } finally {
        inputStream2.close();
        container2.deleteIfExists();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:54,代码来源:GenericTests.java


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