plupload
plupload copied to clipboard
'upload.files.length === 0' after upload.addFile(fileObj);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<script src="./ulupload.js"></script>
<body>
<canvas width="200px" height="200px" style="background-color: black" id='cans'></canvas>
<img src='./baoma.png' id='img'>
<button id='uploadBtn'>upload</button>
</body>
<script>
var cans = document.getElementById('cans');
var ctx = cans.getContext("2d");
//console.log(ctx.drawImage)
var img = document.getElementById('img');
img.onload = function () {
ctx.drawImage(img, 10, 10, 100, 100);
var dataURL = cans.toDataURL();
function dataURLtoFile(dataurl, filename) {
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, { type: mime });
}
const fileObj = dataURLtoFile(dataURL, 'img.png');
var uploader = new plupload.Uploader({
runtimes: 'html5',
url: 'http://oss.aliyuncs.com',
init: {
PostInit: function () {
},
FilesAdded: function (up, files) {
console.log(files,33);
},
FileUploaded: function (up, file, info) {
if (info.status == 200) {
alert('success');
}
else {
alert('error');
}
},
Error: function (up, err) {
console.log(err);
}
}
});
uploader.init();
document.getElementById('uploadBtn').onclick = function () {
uploader.addFile(fileObj,'');
console.log(uploader.files);// [ ];
//uploader.start();
}
}
</script>
</html>
Any movement on this? I'm having exactly the same problem.
same problem, any update?