phonegapを使用してファイルをstreamworkにアップロードしようとしています(https://streamwork.com/api/Post_an_item_File_item.html)。
私はPhonegapのFileTransferAPIを試しましたが、streamworkが要求するようにリクエストを送信していないようです。
var url =getItemsURL();
var item = "<?xml version='1.0' encoding='UTF-8'?>" +
"<item name='Test "+timestamp()+"'>" +
"<description>my upload</description>" +
"<file_item/>" +
"</item>";
var win = function(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
var fail = function(error) {
alert("An error has occurred: Code = "+ error.code);
}
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName="hello.txt";
options.mimeType="text/plain";
var params = new Object();
params.item = item;
options.params = params;
var paths = navigator.fileMgr.getRootPaths();
var ft = new FileTransfer();
ft.upload(paths[0] + "hello.txt",url, win, fail, options);
</code>
(actually I see that phonegap internally throws "java.io.FileNotFoundException: https://streamwork.com/v1/activities/..."
But the url should be correct since I then used the same in a manually written xhr.
function doUpload(data,fname,type,enc){
var url = getItemsURL();
var item = "<?xml version='1.0' encoding='UTF-8'?>" +
"<item name='My new activity item "+timestamp()+"'>" +
"<description>my upload</description>" +
"<file_item/>" +
"</item>";
var xhr = new XMLHttpRequest();
xhr.onreadystatechange=function(){
alert("xmlHttpObject.readyState = " + xhr.readyState + (xhr.readyState >= 3 ? " HTTP-Status = " + xhr.status : ''));
};
xhr.open("POST",url, true);
var boundary ="mime_boundary"
xhr.setRequestHeader("Accept", 'application/xml');
xhr.setRequestHeader("Content-Type", 'multipart/form-data; boundary=' + boundary);
var body = '--' + boundary + '\r\n';
body+='Content-Disposition: form-data; name="item"; filename="dummy.xml"\r\n';
body+= 'Content-Type: application/xml\r\n\r\n';
body+=item+'\r\n';
body+='--'+boundary+'\r\n\r\n';
body+='Content-Disposition: form-data; name="file"; filename="'+fname+'"\r\n';
body+='Content-Type: '+type+'\r\n';
body+='Content-Transfer-Encoding: '+enc+'\r\n\r\n';
body+=data+'--' + boundary + '--\r\n';
xhr.setRequestHeader('Content-length', body.length);
xhr.send(body);
}
which I call with
doUpload("lorem ipsum foo bar","test.txt","text/plain","binary");
これは、Firefoxでドメイン間をクロスする特権を与えると機能しますが、Android(htc Desire hd)で実行すると機能しません。
Firefox xhrのreadystate変更の出力は次のとおりです:1、1、2、4(0)Android xhrのreadystateの変更の出力は次のとおりです:1、4(0)
誰かが私が欠けているものについての考えを持っていますか?
よろしくお願いします