/** * Gets a reference to a blob in this container. The blob must already exist on the service. * * Unlike the other get*Reference methods, this method does a service request to retrieve the blob's metadata and * properties. The returned blob may be used directly as a CloudBlob or cast using either instanceof or * getProperties().getBlobType() to determine its subtype. * * @param blobName * A <code>String</code> that represents the name of the blob. * * @return A {@link CloudBlob} object that represents a reference to the specified blob. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is invalid. */ @DoesServiceRequest public final CloudBlob getBlobReferenceFromServer(final String blobName) throws URISyntaxException, StorageException { return this.getBlobReferenceFromServer(blobName, null, null, null, null); }
/** * Gets a reference to a blob in this container. The blob must already exist on the service. * * Unlike the other get*Reference methods, this method does a service request to retrieve the blob's metadata and * properties. The returned blob may be used directly as a CloudBlob or cast using either instanceof or * getProperties().getBlobType() to determine its subtype. * * @param blobName * A <code>String</code> that represents the name of the blob. * * @return A {@link CloudBlob} object that represents a reference to the specified blob. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is invalid. */ @DoesServiceRequest public final CloudBlob getBlobReferenceFromServer(final String blobName) throws URISyntaxException, StorageException { return this.getBlobReferenceFromServer(blobName, null, null, null, null); }
.getBlobReferenceFromServer(containerService.getKey(file));
.getBlobReferenceFromServer(containerService.getKey(file));
private DescriptiveUrl createSignedUrl(final Path file, int seconds) { final CloudBlob blob; try { if(!session.isConnected()) { return DescriptiveUrl.EMPTY; } blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); } catch(URISyntaxException | StorageException e) { return DescriptiveUrl.EMPTY; } final String token; try { token = blob.generateSharedAccessSignature(this.getPolicy(seconds), null); } catch(InvalidKeyException | StorageException e) { return DescriptiveUrl.EMPTY; } return new DescriptiveUrl(URI.create(String.format("%s://%s%s?%s", Scheme.https.name(), session.getHost().getHostname(), URIEncoder.encode(file.getAbsolute()), token)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(this.getExpiry(seconds)))); }
@Override public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final CloudBlob target = session.getClient().getContainerReference(containerService.getContainer(copy).getName()) .getAppendBlobReference(containerService.getKey(copy)); final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(source).getName()) .getBlobReferenceFromServer(containerService.getKey(source)); final BlobRequestOptions options = new BlobRequestOptions(); options.setStoreBlobContentMD5(PreferencesFactory.get().getBoolean("azure.upload.md5")); final URI s = session.getHost().getCredentials().isTokenAuthentication() ? URI.create(blob.getUri().toString() + session.getHost().getCredentials().getToken()) : blob.getUri(); final String id = target.startCopy(s, AccessCondition.generateEmptyCondition(), AccessCondition.generateEmptyCondition(), options, context); if(log.isDebugEnabled()) { log.debug(String.format("Started copy for %s with copy operation ID %s", copy, id)); } // Copy original file attributes return new Path(copy.getParent(), copy.getName(), copy.getType(), new PathAttributes(source.attributes())); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Cannot copy {0}", e, source); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerReferenceFromServerSAS() throws StorageException, URISyntaxException, IOException, InvalidKeyException { this.container.create(); CloudBlob blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, null, 1024, null); SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy(); Calendar now = Calendar.getInstance(); now.add(Calendar.MINUTE, 10); policy.setSharedAccessExpiryTime(now.getTime()); policy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ)); String token = this.container.generateSharedAccessSignature(policy, null); CloudBlobContainer containerSAS = new CloudBlobContainer(this.container.getStorageUri(), new StorageCredentialsSharedAccessSignature(token)); CloudBlob blobRef = containerSAS.getBlobReferenceFromServer(blob.getName()); assertEquals(blob.getClass(), blobRef.getClass()); assertEquals(blob.getUri(), blobRef.getUri()); }
.getBlobReferenceFromServer(containerService.getKey(file)); final BlobRequestOptions options = new BlobRequestOptions(); blob.downloadAttributes(AccessCondition.generateEmptyCondition(), options, context);
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerReferenceFromServerMissingBlob() throws StorageException, URISyntaxException, IOException { this.container.create(); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("missing"); try { this.container.getBlobReferenceFromServer(blobName); fail("Get reference from server should fail."); } catch (StorageException ex) { assertEquals(404, ex.getHttpStatusCode()); } }
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasSnapshotBlob.exists(); CloudPageBlob copy = this.container.getPageBlobReference("copy");
try { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); final BlobRequestOptions options = new BlobRequestOptions(); options.setConcurrentRequestCount(1);
.getBlobReferenceFromServer(containerService.getKey(file)); found = blob.exists(null, null, context);
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerReferenceFromServer() throws StorageException, URISyntaxException, IOException { this.container.create(); CloudBlob blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, null, 1024, null); blob.getProperties().setContentType("application/octet-stream"); blob.getProperties().setLength(1024); CloudBlob blobRef = this.container.getBlobReferenceFromServer(blob.getName()); BlobTestHelper.assertAreEqual(blob, blobRef); blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.PAGE_BLOB, null, 1024, null); blob.getProperties().setContentType("application/octet-stream"); blob.getProperties().setLength(1024); blobRef = this.container.getBlobReferenceFromServer(blob.getName()); BlobTestHelper.assertAreEqual(blob, blobRef); blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.APPEND_BLOB, null, 1024, null); blob.getProperties().setContentType("application/octet-stream"); blob.getProperties().setLength(1024); blobRef = this.container.getBlobReferenceFromServer(blob.getName()); BlobTestHelper.assertAreEqual(blob, blobRef); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerReferenceFromServerSnapshot() throws StorageException, URISyntaxException, IOException { this.container.create(); CloudBlob blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, null, 1024, null); CloudBlob snapshot = blob.createSnapshot(); snapshot.getProperties().setContentType("application/octet-stream"); snapshot.getProperties().setLength(1024); CloudBlob blobRef = this.container.getBlobReferenceFromServer(snapshot.getName(), snapshot.getSnapshotID(), null, null, null); BlobTestHelper.assertAreEqual(snapshot, blobRef); }
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasSnapshotBlob.exists(); CloudPageBlob copy = this.container.getPageBlobReference(BlobTestHelper.generateRandomBlobNameWithPrefix("copy"));
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasBlob.exists();
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasBlob.exists();
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasBlob.exists();
.getBlobReferenceFromServer(snapshot.getName(), snapshot.getSnapshotID(), null, null, null); sasBlob.exists();