[英]How to Upload files to Puush from Web Server?
我已经找到了一些在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
响应Access-Control-Allow-Origin: http://localhost
(是的,我不只是使用file://协议,因为空源也被拒绝了)。
编辑:原始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
事实证明,请求实际上已完全通过,但由于CORS的性质,响应被拒绝。 因此,文件已上传,但响应引发了错误。 我决定通过我的服务器通过管道发送请求,以解决CORS缺陷。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.