【问题标题】:How to upload image from native android app to GAE (Titanium + GAE)如何将图像从本机 android 应用程序上传到 GAE (Titanium + GAE)
【发布时间】:2014-04-11 10:12:30
【问题描述】:

我想在我的 Android 应用中使用相机拍照,然后将其上传到我的 GAE 服务器。

这是我用来发送图片的代码:

var saveImageView = Titanium.UI.createImageView({
                top : 0,
                left : 0,
                width : 'auto',
                height : 'auto',
                image : event.media,
            });

            win1.add(saveImageView);
            imageToUpload = saveImageView.toBlob();
            // toBlob, not toImage!! important...
            var xhr = Titanium.Network.createHTTPClient();
            xhr.onload = function() {
                win1.remove(saveImageView);
                // remove the temp view...
            };
            xhr.open('POST', 'not sure what goes here');
            xhr.send({
                image : imageToUpload
            });

我不确定我应该使用什么作为服务器的网址。

此外,任何有关 GAE 方面应该是什么样子的帮助都会非常有帮助。

我找到了这个来源:http://www.mstrinity.com/blog/2010/12/29/posting-an-image-from-titanium-to-the-app-engine-data-storage-serving-that-image-out/

但它已经 4 岁了,我根本无法让它工作。

【问题讨论】:

    标签: android google-app-engine


    【解决方案1】:

    posting an image from titanium 文章在 4 年后仍然有效。作者使用'http://10.1.10.15:8888/addimage' 你有'not sure what goes here'。此答案假定您主要希望解释 URL。

    Titan 代码使用专用 IP 地址将图像从 Android 设备上传到专用网络上的 AppEngine 开发服务器(端口 8888)。开发服务器必须接受来自 localhost 以外的传入连接才能正常工作,请参阅this answer 以了解实现此目的的方法。您需要将 IP 地址替换为您自己的 AppEngine 开发计算机的 IP 地址,使用 ifconfig、ipconfig 或类似方法来查找。

    AppEngine 服务器的 python 代码无需修改即可工作,此答案假定您对它感到满意。

    在软件与开发服务器一起工作后,您将部署到例如 AppEngine 云中的“papercuts-image-gallery”。在钛代码中,您应该将10.1.10.15:8888 部分替换为papercuts-image-gallery.appspot.com(没有端口号),但保留URL 字符串的其余部分。如果我是你,我会在 Titan 应用程序代码中保留两个 URL 字符串并使用标志选择一个,以便轻松地将客户端指向开发服务器或生产服务器,而无需重新编译。

    【讨论】:

    • 我似乎无法让 GAE 代码按原样工作。我对 GAE 有一点经验。我应该对 app.yaml 文件或类似文件做些什么来使其工作?谢谢:)
    • 是的,文章省略了app.yaml。有关指导,请参阅 Hello, World! 中创建配置文件下的说明。其实先把你的项目搁置几分钟,先运行教程来验证你的SDK是否正确运行。
    猜你喜欢
    • 2014-05-07
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 2012-09-02
    • 2011-11-01
    • 2012-08-04
    • 2014-10-10
    • 1970-01-01
    相关资源
    最近更新 更多