我正在尝试使用ckeditor上传文件并将文件上传到s3,我已成功将文件上传到s3并返回网址,但是想要在浏览器iframe中向用户显示进度。
使用s3上传器我可以在发射器'进展'
上取得进展 var uploader = client.uploadFile(params);
uploader.on('progress', function () {
var percent = ((parseInt(uploader.progressAmount) * 100) / parseInt(uploader.progressTotal)).toFixed(2);
return callback(null,{type : 'progress', percent: percent, url : null});
});
s3上传
s3uploads(fileUrl, function (err, uploadResult) {
if (err) {
res.send("error");
}
if (uploadResult.type === 'progress') {
html = "<p>Please wait its uploading to server </p> <p>" + uploadResult.percent + "</p>";
console.log(html);
res.write(html);
} else {
fileUrl = uploadResult.url;
res.write("<script type='text/javascript'>\
(function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();\
window.parent.CKEDITOR.tools.callFunction('" + CKEcallback + "','" + fileUrl + "', '" + msg + "');\
</script>");
res.end();
}
});
response.write只显示第一个值,当我尝试传递变量uploadResult.percent时,它会忽略response.write中的值,但是当我执行console.log(html)
时它会显示这个答案让我更加清楚我要做的事情。 https://stackoverflow.com/a/45902781/1391499