public void uploadBlob(final File file, final String containerName, final String blobPath) throws IOException, StorageException, URISyntaxException { CloudBlobContainer container = getCloudBlobContainer(containerName); try (FileInputStream stream = new FileInputStream(file)) { container.getBlockBlobReference(blobPath).upload(stream, file.length()); } }
@Override protected void doPut(String fullPath, ISObject stuff, Map<String, String> attrs) { try { CloudBlockBlob blob = blobContainer.getBlockBlobReference(fullPath); if (!(stuff instanceof SObject.InputStreamSObject)) { blob.upload(stuff.asInputStream(), stuff.getLength()); } BlobProperties props = blob.getProperties(); // content-type contains "-" which is illegal character in C# identifier // so we have to remove it from meta map String contentType = attrs.remove(ISObject.ATTR_CONTENT_TYPE); if (S.notBlank(contentType)) { props.setContentType(contentType); } blob.uploadProperties(); blob.getMetadata().putAll(attrs); blob.uploadMetadata(); } catch (Exception e) { throw E.unexpected(e); } }
@Override public void run() { try { CloudBlobContainer container = blobClient.getContainerReference(azureContainer); container.createIfNotExists(); CloudBlockBlob blob = container.getBlockBlobReference(azureKey); blob.upload(new java.io.FileInputStream(localFile), localFile.length()); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (StorageException e) { throw new RuntimeException(e); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } });
@Override public void create(UUID jobId, String key, InputStream stream) { try { CloudBlobContainer reference = blobClient.getContainerReference(BLOB_CONTAINER); CloudBlockBlob blob = reference.getBlockBlobReference(createRowKey(jobId, key)); blob.upload(stream, UNKNOWN_LENGTH); } catch (StorageException | URISyntaxException | IOException e) { throw new MicrosoftStorageException("Error creating stream for job: " + jobId, e); } }
URL sasUrl = new URL("<sas-url>"); try {. CloudBlockBlob blob = new CloudBlockBlob(sasUrl) File source = new File(filePath); blob.upload(new FileInputStream(source), source.length()); } catch (Exception e) { // Output the stack trace. e.printStackTrace(); }
CloudBlockBlob blob = new CloudBlockBlob(new URI(sasURL)); File source = new File(filePath); blob.upload(new FileInputStream(source), source.length());
/** * Uploads the source stream data to the block blob. If the blob already exists on the service, it will be * overwritten. * * @param sourceStream * An {@link InputStream} object that represents the input stream to write to the block blob. * @param length * A <code>long</code> which represents the length, in bytes, of the stream data, or -1 if unknown. * * @throws IOException * If an I/O error occurred. * @throws StorageException * If a storage service error occurred. */ @Override @DoesServiceRequest public void upload(final InputStream sourceStream, final long length) throws StorageException, IOException { this.upload(sourceStream, length, null /* accessCondition */, null /* options */, null /* opContext */); }
public void uploadBlob(final File file, final String containerName, final String blobPath) throws IOException, StorageException, URISyntaxException { CloudBlobContainer container = getCloudBlobContainer(containerName); try (FileInputStream stream = new FileInputStream(file)) { CloudBlockBlob blob = container.getBlockBlobReference(blobPath); blob.upload(stream, file.length()); } }
@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); } } }
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(); }
@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); } }
@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); } }
private void addMetadataRecordImpl(final InputStream input, String name, long recordLength) throws DataStoreException { try { CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME); CloudBlockBlob blob = metaDir.getBlockBlobReference(name); blob.upload(input, recordLength); } catch (StorageException e) { LOG.info("Error adding metadata record. metadataName={} length={}", name, recordLength, e); throw new DataStoreException(e); } catch (URISyntaxException | IOException e) { throw new DataStoreException(e); } }
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, null, null, AzureStorageUtils.getTalendOperationContext()); }
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, null, null, AzureStorageUtils.getTalendOperationContext()); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testBlobUploadFromStreamTest() throws URISyntaxException, StorageException, IOException { final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); final CloudBlockBlob blockBlobRef = this.container.getBlockBlobReference(blockBlobName); int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); blockBlobRef.upload(srcStream, -1); ByteArrayOutputStream dstStream = new ByteArrayOutputStream(); blockBlobRef.download(dstStream); BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); length = 5 * 1024 * 1024; srcStream = BlobTestHelper.getRandomDataStream(length); blockBlobRef.upload(srcStream, length); dstStream = new ByteArrayOutputStream(); blockBlobRef.download(dstStream); BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); }
@Test public void testBlobUploadFromStreamAccessConditionTest() throws URISyntaxException, StorageException, IOException { final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); final CloudBlockBlob blockBlobRef = this.container.getBlockBlobReference(blockBlobName); AccessCondition accessCondition = AccessCondition.generateIfNotModifiedSinceCondition(new Date()); int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); blockBlobRef.upload(srcStream, -1, accessCondition, null, null); ByteArrayOutputStream dstStream = new ByteArrayOutputStream(); blockBlobRef.download(dstStream); BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); length = 5 * 1024 * 1024; srcStream = BlobTestHelper.getRandomDataStream(length); blockBlobRef.upload(srcStream, length); dstStream = new ByteArrayOutputStream(); blockBlobRef.download(dstStream); BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); }
private void updateBlockBlob(Exchange exchange) throws Exception { CloudBlockBlob client = BlobServiceUtil.createBlockBlobClient(getConfiguration()); configureCloudBlobForWrite(client); BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange); InputStream inputStream = getInputStreamFromExchange(exchange); LOG.trace("Putting a block blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange); try { client.upload(inputStream, -1, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); } finally { closeInputStreamIfNeeded(inputStream); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testBlobEmptyHeaderSigningTest() throws URISyntaxException, StorageException, IOException { final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); final CloudBlockBlob blockBlobRef = this.container.getBlockBlobReference(blockBlobName); final int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); OperationContext context = new OperationContext(); context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(SendingRequestEvent eventArg) { HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject(); connection.setRequestProperty("x-ms-foo", ""); } }); blockBlobRef.upload(srcStream, -1, null, null, context); blockBlobRef.download(new ByteArrayOutputStream(), null, null, context); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testVerifyTransactionalMD5ValidationMissingOverallMD5() throws URISyntaxException, StorageException, IOException { final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); final CloudBlockBlob blockBlobRef = this.container.getBlockBlobReference(blockBlobName); final int length = 2 * 1024 * 1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); BlobRequestOptions options = new BlobRequestOptions(); options.setSingleBlobPutThresholdInBytes(1024*1024); options.setDisableContentMD5Validation(true); options.setStoreBlobContentMD5(false); blockBlobRef.upload(srcStream, -1, null, options, null); options.setDisableContentMD5Validation(false); options.setStoreBlobContentMD5(true); options.setUseTransactionalContentMD5(true); final CloudBlockBlob blockBlobRef2 = this.container.getBlockBlobReference(blockBlobName); blockBlobRef2.downloadRange(1024, (long)1024, new ByteArrayOutputStream(), null, options, null); assertNull(blockBlobRef2.getProperties().getContentMD5()); }