简体   繁体   English

将Azure移动服务表脚本(Blob上传)迁移到Azure App Service

[英]Migrate azure mobile service table script (Blob upload) to azure app service

I'm migrating my app from the old azure mobile service to the new azure app service. 我正在将我的应用程序从旧的Azure移动服务迁移到新的Azure应用程序服务。

And in the old azure mobile service, I use this this table script to insert to my image table. 在旧的Azure移动服务中,我使用此表脚本将其插入到图像表中。

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 + '.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. 
            item.imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path;

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

To migrate, I rewrite it for the new app service, 要迁移,我将其重写为新的应用程序服务,

var table = module.exports = require('azure-mobile-apps').table();
var azure = require('azure');
var qs = require('querystring');
var appSettings = require('mobileservice-config').appSettings;

function insertPhoto(context) {
// Get storage account settings from app settings. 
var accountName = appSettings.STORAGE_ACCOUNT_NAME;
var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
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. 
            item.imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path;

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

table.insert(insertPhoto);

However when I execute it, I got a internal server error, saying Error: Cannot find module 'azure' 但是,当我执行它时,出现内部服务器错误,提示错误:找不到模块“ azure”

Here is the complete error log: 这是完整的错误日志:

2016-05-09T19:02:06  Welcome, you are now connected to log-streaming service.
2016-05-09T19:02:23.812Z - �[31merror�[39m: Unable to load D:\home\site\wwwroot\tables\photos.js Error: Cannot find module 'azure'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous>
(D:\home\site\wwwroot\tables\photos.js:11:13)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)

Mon May 09 2016 19:02:23 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:
Error: Cannot find module 'azure'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous>
    (D:\home\site\wwwroot\tables\photos.js:11:13)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    Application has thrown an uncaught exception and is terminated:
    Error: Cannot find module 'azure'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous>
        (D:\home\site\wwwroot\tables\photos.js:11:13)
        at Module._compile (module.js:435:26)
        at Object.Module._extensions..js (module.js:442:10)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:311:12)
        at Module.require (module.js:366:17)
        at require (module.js:385:17)
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>IIS Detailed Error - 500.1002 - Internal Server Error</title>
            <style type="text/css">
        </head>
        <body>
            <div id="content">
                <div class="content-container">
                    <h3>HTTP Error 500.1002 - Internal Server Error</h3>
                    <h4>The page cannot be displayed because an internal server error has occurred.</h4>
                </div>
                <div class="content-container">
                    <fieldset>
                        <h4>Most likely causes:</h4>
                        <ul>    <li>IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.</li>    <li>IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.</li>    <li>IIS was not able to process configuration for the Web site or application.</li>     <li>The authenticated user does not have permission to use this DLL.</li>   <li>The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.</li> </ul>
                    </fieldset>
                </div>
                <div class="content-container">
                    <fieldset>
                        <h4>Things you can try:</h4>
                        <ul>    <li>Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.</li>     <li>Check the event logs to see if any additional information was logged.</li>  <li>Verify the permissions for the DLL.</li>    <li>Install the .NET Extensibility feature if the request is mapped to a managed handler.</li>  <li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click <a href="http://go.microsoft.com/fwlink/?LinkID=66439">here</a>. </li> </ul>
                    </fieldset>
                </div>

                <div class="content-container">
                    <fieldset>
                        <h4>Detailed Error Information:</h4>
                        <div id="details-left">
                            <table border="0" cellpadding="0" cellspacing="0">
                                <tr class="alt"><th>Module</th><td>&nbsp;&nbsp;&nbsp;iisnode</td></tr>
                                <tr><th>Notification</th><td>&nbsp;&nbsp;&nbsp;ExecuteRequestHandler</td></tr>
                                <tr class="alt"><th>Handler</th><td>&nbsp;&nbsp;&nbsp;iisnode</td></tr>
                                <tr><th>Error Code</th><td>&nbsp;&nbsp;&nbsp;0x00000002</td></tr>

                            </table>
                        </div>
                        <div id="details-right">
                            <table border="0" cellpadding="0" cellspacing="0">
                                <tr class="alt"><th>Requested URL</th><td>&nbsp;&nbsp;&nbsp;http://selfiecontestdev:80/app.js</td></tr>
                                <tr><th>Physical Path</th><td>&nbsp;&nbsp;&nbsp;D:\home\site\wwwroot\app.js</td></tr>
                                <tr class="alt"><th>Logon Method</th><td>&nbsp;&nbsp;&nbsp;Anonymous</td></tr>
                                <tr><th>Logon User</th><td>&nbsp;&nbsp;&nbsp;Anonymous</td></tr>

                            </table>
                            <div class="clear"></div>
                        </div>
                    </fieldset>
                </div>

                <div class="content-container">
                    <fieldset>
                        <h4>More Information:</h4>
                        This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.
                        <p><a href="http://go.microsoft.com/fwlink/?LinkID=62293&amp;IIS70Error=500,1002,0x00000002,9200">View more information &raquo;</a></p>
                        <p>Microsoft Knowledge Base Articles:</p>


                    </fieldset>
                </div>
            </div>
        </body>
    </html>
    {"level":1,"message":"request","timestamp":1462820578207,"responseTime":0,"method":"POST","path":"/dev/api/telemetry/wwwroot/","statusCode":201}
    2016-05-09T19:04:06  No new trace in the past 1 min(s).

Dose anyone know what I should do to fix the script? 有人知道我该怎么做才能修复脚本吗? Thanks in advanced! 提前致谢!

As the architecture of Mobile Apps is changed from Mobile Services, now the mobile apps migrate to Azure App Services. 随着移动应用程序的体系结构从移动服务更改,现在移动应用程序迁移到Azure应用服务。

Actually the Mobile Apps backend in Node.js is an expressjs project, and the mobile app sdk for node is a middleware of express. 实际上,Node.js中的Mobile Apps后端是一个expressjs项目,而node移动应用程序sdk是express的中间件。

So you can download your mobile app to local (refer to How to: Download the Node.js backend quickstart code project using Git ) ,we can leverage package.json file in your application's root directory to maintain the nodejs modules you need, then deploy to Azure via git, and Azure App Service will install the dependencies via deployment task. 因此,您可以将移动应用程序下载到本地(请参阅如何:使用Git下载Node.js后端快速入门代码项目 ),我们可以利用应用程序根目录中的package.json文件来维护所需的nodejs模块,然后进行部署通过git迁移到Azure,Azure App Service将通过部署任务安装依赖项。 You can refer to Using Node.js Modules with Azure applications for more. 您可以参考将Node.js模块与Azure应用程序结合使用以获取更多信息。

Meanwhile, You can leverage Kudu Console site or Visual studio online extension to quick install nodejs module online. 同时,您可以利用Kudu Console网站或Visual Studio在线扩展来在线快速安装nodejs模块。 You can refer to the answer of How to run django manage.py command on Azure App Service for the general idea of these online tools. 您可以参考如何在Azure App Service上运行django manage.py命令的答案了解这些联机工具的一般概念。

Any further concern, please feel free to let me know. 如有任何其他疑问,请随时告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM