Bash で cURL を使用して公式クライアントの外部からアップロードするためのいくつかの回答を見つけましたが、XMLHttpRequest を使用して JavaScript に変換するのは困難です。主な問題は、Puush が CORS をサポートしているとは思えないことです。これまでの私の関連コードは次のとおりです。
var xml = new XMLHttpRequest(),
fd = new FormData();
xml.open("POST", "http://puush.me/api/up", true);
xml.withCredentials = true; //I've tried with and without this line, neither seems to work
//the following variables are specified from cURL demos I found
fd.append("z", "poop"); //I honestly don't get this part
fd.append("e", "username@domain.com");
fd.append("k", apiKey); //which I copied from my account settings on Puush
fd.append("f", input.files[0]); //where "input" is <input type="file"/>
//add event handlers
xml.addEventListener("progress", progress);
xml.addEventListener("load", loaded);
xml.addEventListener("error", error);
xml.addEventListener("abort", aborted);
xml.send(fd); //send the FormData as a "multipart/form-data" request
何を試しても常に同じ応答が返され、エラーハンドラーが常に呼び出され、サーバーが応答しなかったことを示すコンソールのエラーログが表示されますAccess-Control-Allow-Origin: http://localhost
(はい、単に file:// を使用しただけではありませんnull オリジンも拒否されたため)。
編集:元の bash コードは次のリンクにあります:
http://pastebin.com/ZnbY91EA
https://github.com/nekodex/lazymode/blob/master/puush/puu.sh
https://github.com /blha303/puush-linux/blob/master/puush
https://github.com/NickHu/puush-linux/blob/master/puush