我找到了一些在 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
(是的,我不只是简单地使用文件://协议,因为 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