Skip to content

Commit

Permalink
Merge pull request #8 from veena-udayabhanu/master
Browse files Browse the repository at this point in the history
Storage Client Library - 0.3.0
  • Loading branch information
vinaysh-msft committed Jul 7, 2014
2 parents ee3e226 + 9bfb480 commit 019c38a
Show file tree
Hide file tree
Showing 31 changed files with 6,842 additions and 1,174 deletions.
8 changes: 8 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Note: This is an Azure Storage only package. The all up Azure node sdk still has the old storage bits in there. In a future release, those storage bits will be removed and an npm dependency to this storage node sdk will
be taken. This is a CTP v1 release and the changes described below indicate the changes from the Azure node SDK 0.9.8 available here - https://github.com/Azure/azure-sdk-for-node.

2014.07.07 Version 0.3.0

BLOB
* Fixed a bug which failed to return single item blocklists while doing listBlocks.

FILE
* Added File Service support. The File Service and the associated APIs are in preview.

2014.07.01 Version 0.2.1

ALL
Expand Down
68 changes: 64 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ This project provides a Node.js package that makes it easy to consume and manage
- Query/Create/Read/Update/Delete Entities
- Blobs
- Create/Read/Update/Delete Blobs
- Files
- Create/Update/Delete Directories
- Create/Read/Update/Delete Files
- Queues
- Create/Delete Queues
- Insert/Peek Queue Messages
Expand Down Expand Up @@ -128,21 +131,21 @@ blobService.createContainerIfNotExists('taskcontainer', {publicAccessLevel : 'bl
});
```

To upload a file (assuming it is called task1-upload.txt and it is placed in the same folder as the script below), the method **createBlockBlobFromFile** can be used.
To upload a file (assuming it is called task1-upload.txt and it is placed in the same folder as the script below), the method **createBlockBlobFromLocalFile** can be used.

```Javascript
var azure = require('azure-storage');
var blobService = azure.createBlobService();

blobService.createBlockBlobFromFile('mycontainer', 'taskblob', 'task1-upload.txt', function(error, result, response){
blobService.createBlockBlobFromLocalFile('mycontainer', 'taskblob', 'task1-upload.txt', function(error, result, response){
if(!error){
// file uploaded
}
});
```


For page blobs, use **createPageBlobFromFile**. There are other methods for uploading blobs also, such as **createBlockBlobFromText** or **createPageBlobFromStream**.
For page blobs, use **createPageBlobFromLocalFile**. There are other methods for uploading blobs also, such as **createBlockBlobFromText** or **createPageBlobFromStream**.

There are also several ways to download block and page blobs. For example, **getBlockBlobToStream** downloads the blob to a stream:

Expand Down Expand Up @@ -224,6 +227,63 @@ queueService.getMessages(queueName, function(error, serverMessages){
});
```

### File Storage

The **createShareIfNotExists** method can be used to create a
share in which to store a file or a directory of files:

```Javascript
var azure = require('azure-storage');
var fileService = azure.createFileService();
fileService.createShareIfNotExists('taskshare', function(error, result, response){
if(!error){
// if result = true, share was created.
// if result = false, share already existed.
}
});
```

To create a directory, the method **createDirectoryIfNotExists** can be used.

```Javascript
var azure = require('azure-storage');
var fileService = azure.createFileService();

fileService.createDirectoryIfNotExists('taskshare', 'taskdirectory', function(error, result, response){
if(!error){
// if result = true, share was created.
// if result = false, share already existed.
}
});
```

To upload a file (assuming it is called task1-upload.txt and it is placed in the same folder as the script below), the method **createFileFromLocalFile** can be used.

```Javascript
var azure = require('azure-storage');
var fileService = azure.createFileService();

fileService.createFileFromLocalFile('taskshare', 'taskdirectory', 'taskfile', 'task1-upload.txt', function(error, result, response){
if(!error){
// file uploaded
}
});
```

There are other methods for uploading files also, such as **createFileFromText** or **createFileFromStream**.

There are also several ways to download files. For example, **getFileToStream** downloads the file to a stream:

```Javascript
var fileService = azure.createFileService();
var fs = require('fs');
fileService.getFileToStream('taskshare', 'taskdirectory', 'taskfile', fs.createWriteStream('output.txt'), function(error, result, response){
if(!error) {
// file retrieved
}
});
```

## Code Samples

How-Tos focused around accomplishing specific tasks are available on the [Microsoft Azure Node.js Developer Center](http://azure.microsoft.com/en-us/develop/nodejs/).
Expand All @@ -236,7 +296,7 @@ How-Tos focused around accomplishing specific tasks are available on the [Micros

# Running Tests

In order to run the tests, the following environment variables need to be set up using an admin command prompt:
In order to run the tests, the following environment variables need to be set up:

AZURE_STORAGE_CONNECTION_STRING="valid storage connection string"

Expand Down
2 changes: 1 addition & 1 deletion examples/blobuploader/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ app.post('/uploadhandler', function (req, res) {
metadata: { fileName: newName }
};

blobClient.createBlockBlobFromFile(containerName, fields.itemName, files.uploadedFile.path, options, function (error) {
blobClient.createBlockBlobFromLocalFile(containerName, fields.itemName, files.uploadedFile.path, options, function (error) {
if (error != null) {
helpers.renderError(res);
} else {
Expand Down
4 changes: 2 additions & 2 deletions examples/samples/blobuploaddownloadsample.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function uploadBlobs(sourceDirectoryPath, containerName, callback) {
files.forEach(function (file) {
var blobName = file.replace(/^.*[\\\/]/, '');

blobService.createBlockBlobFromFile(containerName, blobName, file, function (error) {
blobService.createBlockBlobFromLocalFile(containerName, blobName, file, function (error) {
finished++;

if (error) {
Expand Down Expand Up @@ -155,7 +155,7 @@ function downloadBlobs(containerName, destinationDirectoryPath, callback) {
var blobsDownloaded = 0;

blobs.forEach(function (blob) {
blobService.getBlobToFile(containerName, blob.name, destinationDirectoryPath + '/' + blob.name, function (error2) {
blobService.getBlobToLocalFile(containerName, blob.name, destinationDirectoryPath + '/' + blob.name, function (error2) {
blobsDownloaded++;

if (error2) {
Expand Down
24 changes: 24 additions & 0 deletions lib/azure-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,30 @@ exports.createBlobServiceAnonymous = function (host) {
return new BlobService(null, null, host, null);
};

/**
* File client exports.
* @ignore
*/
var FileService = require('./services/file/fileservice');

exports.FileService = FileService;
exports.FileUtilities = require('./services/file/fileutilities');

/**
* Creates a new {@link FileService} object.
* If no storageaccount or storageaccesskey are provided, the AZURE_STORAGE_CONNECTION_STRING and then the AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY
* environment variables will be used.
*
* @param {string} storageAccountOrConnectionString The storage account or the connection string.
* @param {string} [storageAccessKey] The storage access key.
* @param {string|object} [host] The host address. To define primary only, pass a string.
* Otherwise 'host.primaryHost' defines the primary host and 'host.secondaryHost' defines the secondary host.
* @return {FileService} A new FileService object.
*/
exports.createFileService = function (storageAccountOrConnectionString, storageAccessKey, host) {
return new FileService(storageAccountOrConnectionString, storageAccessKey, host);
};

/**
* Queue client exports.
* @ignore
Expand Down
35 changes: 28 additions & 7 deletions lib/common/services/storageservicesettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ var tableEndpointSetting = ServiceSettings.settingWithFunc(
Validate.isValidHost
);

var fileEndpointSetting = ServiceSettings.settingWithFunc(
ConnectionStringKeys.FILE_ENDPOINT_NAME,
Validate.isValidHost
);

var validKeys = [
ConnectionStringKeys.USE_DEVELOPMENT_STORAGE_NAME,
ConnectionStringKeys.DEVELOPMENT_STORAGE_PROXY_URI_NAME,
Expand All @@ -58,7 +63,8 @@ var validKeys = [
ConnectionStringKeys.SHARED_ACCESS_SIGNATURE_NAME,
ConnectionStringKeys.BLOB_ENDPOINT_NAME,
ConnectionStringKeys.QUEUE_ENDPOINT_NAME,
ConnectionStringKeys.TABLE_ENDPOINT_NAME
ConnectionStringKeys.TABLE_ENDPOINT_NAME,
ConnectionStringKeys.FILE_ENDPOINT_NAME
];

/**
Expand All @@ -70,16 +76,18 @@ var validKeys = [
* @param {string} blobEndpoint The storage service blob endpoint.
* @param {string} queueEndpoint The storage service queue endpoint.
* @param {string} tableEndpoint The storage service table endpoint.
* @param {string} fileEndpoint The storage service file endpoint.
* @param {bool} usePathStyleUri Boolean value indicating wether to use path style uri or not.
*/
function StorageServiceSettings(name, key, sasToken, blobEndpoint, queueEndpoint, tableEndpoint, usePathStyleUri) {
function StorageServiceSettings(name, key, sasToken, blobEndpoint, queueEndpoint, tableEndpoint, fileEndpoint, usePathStyleUri) {
this._name = name;
this._key = key;
this._sasToken = sasToken;

this._blobEndpoint = blobEndpoint;
this._queueEndpoint = queueEndpoint;
this._tableEndpoint = tableEndpoint;
this._fileEndpoint = fileEndpoint;

if (usePathStyleUri) {
this._usePathStyleUri = usePathStyleUri;
Expand Down Expand Up @@ -124,6 +132,7 @@ StorageServiceSettings.createExplicitly = function (storageAccount, storageAcces
addIfNotNullOrEmpty('blobendpoint', host);
addIfNotNullOrEmpty('tableendpoint', host);
addIfNotNullOrEmpty('queueendpoint', host);
addIfNotNullOrEmpty('fileendpoint', host);
} else {
addIfNotNullOrEmpty('defaultendpointsprotocol', ServiceSettings.DEFAULT_PROTOCOL.split(':', 1)[0]);
}
Expand Down Expand Up @@ -189,7 +198,8 @@ StorageServiceSettings.createFromSettings = function (settings) {
ServiceSettings.optional(
blobEndpointSetting,
queueEndpointSetting,
tableEndpointSetting
tableEndpointSetting,
fileEndpointSetting
)
);

Expand All @@ -207,7 +217,8 @@ StorageServiceSettings.createFromSettings = function (settings) {
ServiceSettings.atLeastOne(
blobEndpointSetting,
queueEndpointSetting,
tableEndpointSetting
tableEndpointSetting,
fileEndpointSetting
)
);

Expand All @@ -224,7 +235,8 @@ StorageServiceSettings.createFromSettings = function (settings) {
ServiceSettings.atLeastOne(
blobEndpointSetting,
queueEndpointSetting,
tableEndpointSetting
tableEndpointSetting,
fileEndpointSetting
)
);

Expand All @@ -240,7 +252,7 @@ StorageServiceSettings.createFromSettings = function (settings) {
blobEndpointSetting
),
ServiceSettings.optional(
blobEndpointSetting,
fileEndpointSetting,
queueEndpointSetting,
tableEndpointSetting
)
Expand Down Expand Up @@ -292,6 +304,7 @@ StorageServiceSettings.getDevelopmentStorageAccountSettings = function (proxyUri
blobEndpoint,
queueEndpoint,
tableEndpoint,
null,
true
);
};
Expand All @@ -304,6 +317,7 @@ StorageServiceSettings.getDevelopmentStorageAccountSettings = function (proxyUri
* @param {string} blobEndpointUri The blob endpoint uri.
* @param {string} queueEndpointUri The queue endpoint uri.
* @param {string} tableEndpointUri The table endpoint uri.
* @param {string} fileEndpointUri The file endpoint uri.
* @return {StorageServiceSettings}
*/
StorageServiceSettings._createStorageServiceSettings = function (settings) {
Expand Down Expand Up @@ -362,14 +376,21 @@ StorageServiceSettings._createStorageServiceSettings = function (settings) {
scheme,
StorageServiceClientConstants.CLOUD_TABLE_HOST);

var fileEndpoint = standardizeHost(
util.tryGetValueInsensitive(ConnectionStringKeys.FILE_ENDPOINT_NAME, settings),
accountName,
scheme,
StorageServiceClientConstants.CLOUD_FILE_HOST);


return new StorageServiceSettings(
accountName,
accountKey,
sasToken,
blobEndpoint,
queueEndpoint,
tableEndpoint
tableEndpoint,
fileEndpoint
);
};

Expand Down
Loading

0 comments on commit 019c38a

Please sign in to comment.