这必须很接近,但我无法弄清楚导致错误的原因。
在我的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.
更多推荐
发布评论