【问题标题】:Upload an image to Drupal 7 / Services 3 from Titanium?从 Titanium 将图像上传到 Drupal 7 / Services 3?
【发布时间】:2012-11-18 05:36:00
【问题描述】:

这一定很接近,但我不知道是什么导致了错误。

在我的 Titanium 应用程序中,我有一个带有画布元素的 Webview 和以下代码:

function getImageData() {
    return canvas.toDataURL('image/png');
}

我正在像这样将该数据移动到 Titanium 应用程序:

var imageBase64data = webview.evalJS('getImageData()')

以“data:image/png;base64”开头的数据看起来不错...

然后在 Titanium 中,我有一个登录的 drupal 会话并调用此函数:

function uploadImage(imageBase64data, callback) {

    var url = REST_PATH + "file.json";

    var file = { 
        filename: utils.createRandomString() + ".png",
        file: imageBase64data
//      uid: Titanium.App.Properties.getString("userUid"),
//      filesize: ""+Titanium.Utils.base64decode(imageBase64data).length,
    };


    var xhr = Titanium.Network.createHTTPClient({timeout: 30000});

    xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    var authString = Titanium.App.Properties.getString("userSessionName")+'='+Titanium.App.Properties.getString("userSessionId");
    xhr.setRequestHeader("Cookie", authString);

    xhr.onload = function() {
        if(xhr.status == 200) {

            var response = xhr.responseText;

            callback(response);
        }
    };

    xhr.onerror = function(e) {
      alert("There was an error: " + e.error);

      Ti.API.info(JSON.stringify(this));
    };    

    xhr.open("POST", url);
    xhr.send(file);
}

xhr.onerror 被 e.error = "undefined" 调用

轨迹如下所示:

{
  "responseData":{},
  "readyState":4,
  "connected":true,"UNSENT":0,"DONE":4,"HEADERS_RECEIVED":2,"OPENED":1,"LOADING":3,
  "responseText":null,"status":406
}

我认为身份验证有效,因为在添加 Cookie 标头之前,我之前收到“需要身份验证”错误。

【问题讨论】:

    标签: web-services drupal drupal-7 titanium drupal-services


    【解决方案1】:

    这是 Drupanium 提供的安装。我刚刚安装了全新的 Drupal 和 Services 3,我的文件上传得很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 2013-07-31
      • 1970-01-01
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-04
      相关资源
      最近更新 更多