【问题标题】:Azure Node.js querystring return nothing when attempting to stringify object尝试对对象进行字符串化时,Azure Node.js 查询字符串不返回任何内容
【发布时间】:2016-08-17 02:15:56
【问题描述】:

我正在尝试对共享访问查询字符串 url 进行字符串化。但是它什么也不返回。下面是代码:

var table = module.exports = require('azure-mobile-apps').table();
var azure = require('azure');
var qs = require('querystring');
var logger = require('azure-mobile-apps/src/logger');

// table.read(function (context) {
//     return context.execute();
// });

 // table.read.use(customMiddleware, table.operation);

 table.insert(function (context) {
// Get storage account settings from app settings. 
var accountName = 'xxx';
var accountKey = 'xxx';
var host = accountName + '.blob.core.windows.net';

if ((typeof context.item.containerName !== "undefined") && (
context.item.containerName !== null)) {
    // Set the BLOB store container name on the item, which must be lowercase.
    context.item.containerName = context.item.containerName.toLowerCase();

    // If it does not already exist, create the container 
    // with public read access for blobs.        
    var blobService = azure.createBlobService(accountName, accountKey, host);
    blobService.createContainerIfNotExists(context.item.containerName, {
        publicAccessLevel: 'blob'
    }, function(error) {
        if (!error) {

            // Provide write access to the container for the next 5 mins.        
            var sharedAccessPolicy = {
                AccessPolicy: {
                    Permissions: azure.Constants.BlobConstants.SharedAccessPermissions.WRITE,
                    Expiry: new Date(new Date().getTime() + 5 * 60 * 1000)
                }
            };

            // Generate the upload URL with SAS for the new image.
            var sasQueryUrl = 
            blobService.generateSharedAccessSignature(context.item.containerName, 
            context.item.resourceName, sharedAccessPolicy);

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

            // Set the full path on the new new item, 
            // which is used for data binding on the client. 
            context.item.imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path;
            logger.debug('h); e); l); l); o)'); 
            logger.debug(sasQueryUrl);
            logger.debug(context.item.sasQueryString);
        } else {
            console.error(error);
            logger.error(error);                           
        }
        return context.execute();
    });
} else {
    return context.execute();
}   

});

记录器的输出返回:

2016-08-16T13:50:24.820Z - debug: h); e); l); l); o)

2016-08-16T13:50:24.836Z - debug: se=2016-08-16T13%3A55%3A24Z&sp=w&sv=2015-   04-05&sr=b&sig=euf53CcO8SDqJowFBFiKPgRTpVt21HmRUlppN9piatY%3D

2016-08-16T13:50:24.852Z - debug: 

如您所见,当 se=2016-08-16T13%3A55%3A24Z&sp=w&sv=2015-04-05&sr=b&sig=euf53CcO8SDqJowFBFiKPgRTpVt21HmRUlppN9piatY%3D 无法返回 queryString、baseUrl 和小路。

我尝试在控制台中安装 npm querystring 并尝试运行它,但仍然无法正常工作。这是我参考的教程。

https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-upload-data-blob-storage/

太糟糕了,新版本的门户与教程不兼容,因此我尝试将代码移植到新版本。

谢谢。

【问题讨论】:

  • 您可能应该将 SAS 令牌生成作为自定义 API。有关文件上传的信息,请参阅shellmonger.com/2016/05/30/…。您应该能够与 Android 教程集成。

标签: android node.js azure azure-mobile-services


【解决方案1】:

您链接的 URL 中的示例对于当前版本的 azure 包已过期。 blobService.generateSharedAccessSignature 方法现在直接返回查询字符串,而不是包含查询字符串、baseUrl 和路径属性的对象。您根本不需要使用querystring.stringify 方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2017-03-22
    • 1970-01-01
    相关资源
    最近更新 更多