【问题标题】:Populate backend datastore with data using upload script使用上传脚本使用数据填充后端数据存储
【发布时间】:2014-04-02 04:25:48
【问题描述】:

我正在学习本教程,但由于很多部分没有向初学者解释,因此遇到了很多麻烦:https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial

我来到了我们需要将一些数据上传到数据存储区的部分。他们正在使用.csv 文件来完成此操作。

这是我坚持的教程的一部分:

Create Upload Script

This is the script that actually uploads the simulated information into the backend datastore.

For information about the bulkloader.yaml and more, refer to the App Engine documentation in: Uploading and Downloading Data. Also, you can find the bulkloader.yaml file and the test data here MobileAssistant-Data.

Create a new directory and make it your current directory.
In your editor, create a script file and call it upload_data.sh.
Copy and paste the following code into the file.
#!/bin/sh
appcfg.py upload_data
--config_file bulkloader.yaml --url=http://localhost:8888/remote_api --filename $1 --kind=$2 -e
nobody@nowhere.com
The previous script accepts two arguments separated by a blank space:

./upload_data.sh<data.csv> <class entity name>

The first argument is the name of the csv file that contains the data you want to upload, The second is the name of the entity class to handle the data.

Close and save the file. Notice that the script at this time is intended to be used on local server. It must be modified when the backend application is deployed to the cloud. For example, e-mail “nobody@nowhere.com ” will be changed to an actual e-mail address of the App Engine administrator before deployment.
Places Simulated Data

The simulated data is contained in the file places.csv that you downloaded earlier from the MobileAssistant-Data directory in Mobile Shopping Assistant.

The file contains the following comma separated fields:

name: <place’s name>
placeId: <number that identifies the place>
location: <place’s latitude and longitude coordinates (two values separated by a comma) >
key: <unique key associated with the place>
address: <the place’s address >
Modify Web.xml

To upload data to the datastore, reference the “remote API servlet” and associate it with a URL. You’ll define these mappings in the Web.xml file of the MobileAssistant-Appengine application, as shown next. The web server uses this configuration to identify the servlet to handle a given request.

Note. Notice, you might need to restart Eclipse. if you skip th e Web.xml modification you will get Error 404 Not Found.

<servlet>
<display-name>Remote API Servlet</display-name>
<servlet-name>RemoteApiServlet</servlet-name>
<servlet-class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RemoteApiServlet</servlet-name>
<url-pattern>/remote_api</url-pattern>
</servlet-mapping>
Upload Places Simulated Data

To upload the test data to the data store, run the script that uploads the data from your script directory.

Before you upload your data, make sure to start MobileAssistant-AppEngine as a Web Application (in Debug mode) in Eclipse.

./upload_data.sh <places.csv> Place
At the password request, just press enter.

我不明白脚本的那部分。我在桌面上创建了一个文件夹age,放在他们的文件bulkloader.yaml 和places.csv 中。在那个文件夹里面是那个上传脚本。

在我运行 ./upload_data.sh &lt;places.csv&gt; Place 后,在我的终端中收到以下错误:

upload_data.sh: line 2: appcfg.py: command not found
upload_data.sh: line 3: --config_file: command not found
upload_data.sh: line 4: nobody@nowhere.com: command not found

我应该如何将该数据上传到 Google App Engine 数据存储区?谢谢。

【问题讨论】:

    标签: macos google-app-engine csv google-cloud-datastore


    【解决方案1】:

    appcfg.py 是否在您的路径中,如果没有,则在脚本中明确设置路径或将 appcfg.py 的路径添加到您的 PATH 中

    【讨论】:

    • 感谢您的建议,但我真的不确定我需要做什么。我应该把我的脚本放在哪里以及如何找到 appcfg.py?我在我的 MAC 上的任何地方都没有看到该文件。
    • appcfg.py 会在您安装 google_appengine SDK 的位置找到。
    • 我安装了 Eclipse GAE 插件,现在我看到我有appcfg.sh,而不是appcfg.py。我将它复制到我的文件夹,但现在我收到一条消息 appcfg.sh 找不到。
    • 你不能这样做,除非你对路径有特定的了解。您确实需要花一些时间来了解如何设置可执行权限、如何在命令行上进行路径搜索以及如何实际查找内容。我不使用 eclipse 或 OS/X,所以我不知道你在哪里安装了东西。但这也是非常基本的 unix/linux 技能,如果我在你的位置上,我会了解这个级别的情况。
    猜你喜欢
    • 2016-01-16
    • 2018-12-16
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    • 2019-03-22
    • 1970-01-01
    相关资源
    最近更新 更多