无法为表存储生成共享访问签名

时间:2015-11-20 04:42:58

标签: android azure azure-table-storage

我尝试使用以下代码为我的Android应用生成共享访问签名以访问Azure表存储,但我无法使其工作。我收到服务器错误,请参阅日志。问题似乎与tableService.generateSharedAccessSignature(item.tableName,sharedAccessPolicy)有关。有人可以解释一下我做错了什么吗?谢谢。

var azure = require('azure');
var qs = require('querystring');
var appSettings = require('mobileservice-config').appSettings;

function insert(item, user, request) {

      // Get storage account settings from app settings. 
    var accountName = appSettings.STORAGE_ACCOUNT_NAME;
    var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
    var host = accountName + '.table.core.windows.net';

    if ((typeof item.tableName !== "undefined") && (
    item.tableName !== null)) {
        // Set the Table store table name on the item, which must be lowercase.
        item.tableName = item.tableName.toLowerCase();

        // If it does not already exist, create the table       
        var tableService = azure.createTableService(accountName, accountKey, host);
        tableService.createTableIfNotExists(item.tableName, function(error) {
            if (!error) {

                // Provide write access to the container for the next 5 mins.        
                var sharedAccessPolicy = {
                    AccessPolicy: {
                     Permissions: "raud",
                        Expiry: minutesFromNow(50)
                    }
                };

                // Generate.
                var sasQueryUrl = 
                tableService.generateSharedAccessSignature(item.tableName, sharedAccessPolicy);

                // Set the query string.
                item.sasQueryString = qs.stringify(sasQueryUrl.queryString);

                item.tokenExpireDate = minutesFromNow(50);

            } else {
                console.error(error);
            }
            request.execute();
        });
    } else {
        request.execute();
    }

    function minutesFromNow(minutes) {
    var date = new Date()
    date.setMinutes(date.getMinutes() + minutes);
    return date;
  }
}

记录条目详细信息

ERROR
TypeError: Object [object Object] has no method 'generateSharedAccessSignature'
    at </table/Storage.insert.js>:33:30
    at TableService.createTableIfNotExists (D:\home\site\wwwroot\node_modules\azure\lib\services\table\tableservice.js:269:5)
    at TableService.createTable.finalCallback (D:\home\site\wwwroot\node_modules\azure\lib\services\table\tableservice.js:236:7)
    at ServiceClient._initDefaultFilter.filter (D:\home\site\wwwroot\node_modules\azure\lib\services\core\serviceclient.js:538:11)
    at TableService.createTable.processResponseCallback (D:\home\site\wwwroot\node_modules\azure\lib\services\table\tableservice.js:239:5)
    at Request.ServiceClient._performRequest.self._buildRequestOptions.processResponseCallback [as _callback] (D:\home\site\wwwroot\node_modules\azure\lib\services\core\serviceclient.js:206:9)
    at Request.init.self.callback (D:\home\site\wwwroot\node_modules\azure\node_modules\request\main.js:122:22)
    at Request.EventEmitter.emit (events.js:99:17)
    at Request.<anonymous> (D:\home\site\wwwroot\node_modules\azure\node_modules\request\main.js:655:16)
    at Request.EventEmitter.emit (events.js:126:20)

0 个答案:

没有答案