本文整理汇总了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;
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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;
}
示例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();
}
示例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]);
}
示例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.");
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
}