将图像从Titanium上传到Drupal 7 / Services 3?(Upload an image to Drupal 7 / Services 3 from Titanium?)

编程入门 行业动态 更新时间:2024-10-26 02:29:20
图像从Titanium上传到Drupal 7 / Services 3?(Upload an image to Drupal 7 / Services 3 from Titanium?)

这必须很接近,但我无法弄清楚导致错误的原因。

在我的Titanium应用程序中,我有一个带有canvas元素的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); }

用e.error =“undefined”调用xhr.onerror

跟踪看起来像这样:

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

我认为身份验证工作正常,因为我之前收到了“需要身份验证”错误,直到我添加了Cookie标头。

This must be close but I can't figure out what's causing the error.

In my Titanium app, I have a Webview with a canvas element and this code:

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

I am moving that data to the Titanium app like this:

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

The data looks good starting with "data:image/png;base64,"...

Then in Titanium, I have a logged-in drupal session and call this function:

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 is being called with e.error = "undefined"

The trace looks like this:

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

I think authentication is working because I was previously getting a "need authentication" error until I added the Cookie header.

最满意答案

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

That was with the installation provided by Drupanium. I just did a fresh Drupal and fresh Services 3 install and my file is uploading nicely.

更多推荐

本文发布于:2023-08-06 18:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454265.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   Titanium   Drupal   image   Upload

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!