Skip to content

Commit

Permalink
Merge pull request Azure#10 from andrerod/dev
Browse files Browse the repository at this point in the history
Adding getBlobUrl method.
  • Loading branch information
Andre Rodrigues committed Dec 14, 2011
2 parents 23c3d99 + 6dd19c8 commit a2a24da
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/services/blob/blobservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,32 @@ BlobService.prototype.generateSharedAccessSignature = function (container, blob,
};
};

/**
* Retrieves a blob URL.
*
* @this {BlobService}
* @param {string} container The container name.
* @param {string} [blob] The blob name.
* @return {string}
*/
BlobService.prototype.getBlobUrl = function (container, blob) {
// Validate container name. Blob name is optional.
validateContainerName(container);

var resourceName = createResourceName(container, blob);

var baseUrl = this.protocol + this.getHostname() + ':' + this.port;
var path = this.getPath('/' + resourceName);

return {
baseUrl: baseUrl,
path: path,
url: function () {
return baseUrl + path;
}
};
};

// Private methods

/**
Expand Down
23 changes: 23 additions & 0 deletions test/services/blob/blobservice-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,29 @@ module.exports = testCase(
});
});
});
},

testGetBlobUrl: function (test) {
var containerName = testutil.generateId(containerNamesPrefix, containerNames);
var blobName = testutil.generateId(blobNamesPrefix, blobNames);

var blobServiceTest = azure.createBlobService('storageAccount', 'storageAccessKey', 'host:80');
blobServiceTest.usePathStyleUri = false;

var urlParts = blobServiceTest.getBlobUrl(containerName);
test.equal(urlParts.url(), 'http://storageAccount.host:80/' + containerName);

urlParts = blobServiceTest.getBlobUrl(containerName, blobName);
test.equal(urlParts.url(), 'http://storageAccount.host:80/' + containerName + '/' + blobName);

blobServiceTest.usePathStyleUri = true;
urlParts = blobServiceTest.getBlobUrl(containerName);
test.equal(urlParts.url(), 'http://host:80/storageAccount/' + containerName);

urlParts = blobServiceTest.getBlobUrl(containerName, blobName);
test.equal(urlParts.url(), 'http://host:80/storageAccount/' + containerName + '/' + blobName);

test.done();
}
});

Expand Down

0 comments on commit a2a24da

Please sign in to comment.