Check for local SQL Server instances by one of the below
tools:
svrnetcnSQLCMD –L
OSQL –L
Run Storage Emulator from command line:
c:\Program Files (x86)\Microsoft SDKs\Azure\Storage
Emulator>c:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator>WAStorageEmulator init /forceCreate
c:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator>WAStorageEmulator.exe start
Verify the icon on the task bar:
Mouse over the icon should:
Right-Click on the icon:
Select Show Storage Emulator UI: (validation)
The port number and the other configuration can be found
in C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\WAStorageEmulator.exe.config
Telnet to Storage Emulator: (alternative validation)
c:\Program Files (x86)\Microsoft SDKs\Azure\Storage
Emulator>telnet localhost 10000
Type “^]” (without the quotes to exit)
netstat –natf –p tcp (alternative validation)
Test in code:
package com.mycos.dpweb;
import java.io.File;
import
java.io.FileInputStream;
import
java.io.FileOutputStream;
import
com.microsoft.azure.storage.*;
import
com.microsoft.azure.storage.blob.*;
public class BlobEmulatorTest {
// Define the
connection-string with your values
// public
static final String storageConnectionString = "DefaultEndpointsProtocol=http;"
// +
"AccountName=devstoreaccount1;"
// +
"AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
// // Retrieve
storage account from connection-string.
// public static
String storageConnectionString =
//
RoleEnvironment.getConfigurationSettings().get("StorageConnectionString");
public static void main(String[] args) {
try {
// Retrieve storage
account from connection-string.
// CloudStorageAccount
storageAccount = CloudStorageAccount
// .parse(storageConnectionString);
CloudStorageAccount
storageAccount =
CloudStorageAccount.getDevelopmentStorageAccount();
// Create the blob
client.
CloudBlobClient
blobClient = storageAccount.createCloudBlobClient();
// Get a reference
to a container.
// The container
name must be lower case
CloudBlobContainer
container = blobClient
.getContainerReference("mycontainer");
// Create the
container if it does not exist.
container.createIfNotExists();
// Create a
permissions object.
BlobContainerPermissions
containerPermissions = new
BlobContainerPermissions();
// Include public
access in the permissions object.
containerPermissions
.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
// Set the
permissions on the container.
container.uploadPermissions(containerPermissions);
// Define the path
to a local file.
final String filePath = "C:\\dev\\demo\\Test.txt";
// Create or
overwrite the "myimage.jpg" blob with contents from a
// local file.
CloudBlockBlob
blob = container.getBlockBlobReference("Test.txt");
File
source = new File(filePath);
blob.upload(new FileInputStream(source), source.length());
// Loop over blobs
within the container and output the URI to each
// of them.
for (ListBlobItem blobItem : container.listBlobs()) {
System.out.println(blobItem.getUri());
}
// Loop through
each blob item in the container.
for (ListBlobItem blobItem : container.listBlobs()) {
// If the item is a
blob, not a virtual directory.
if (blobItem instanceof CloudBlob) {
// Download the
item and save it to a file with the same
// name.
CloudBlob
blob1 = (CloudBlob) blobItem;
blob1.download(new FileOutputStream(
"C:\\dev\\demo\\dwnld\\" + blob1.getName()));
}
}
}
catch (Exception e) {
// Output the stack
trace.
e.printStackTrace();
}
}
}
No comments:
Post a Comment