Answer the question
In order to leave comments, you need to log in
How to do multi file upload using paste event js?
How to do multi file upload using paste event js ?
I want to make a multi-load image through the buffer, but it doesn't work, all the time it seems like one file gets into e.clipboardData.items. And
function pasteHandler(e) {
// если поддерживается event.clipboardData (Chrome)
var filesArr = [];
// console.log(e.clipboardData.getData("text/plain"));
if (e.clipboardData) {
// получаем все содержимое буфера
var items = e.clipboardData.items;
if (items) {
// находим изображение
console.log(e);
for (var i = 0; i < items.length; i++) {
console.log(i, items[i].type);
if (items[i].type.indexOf("image") !== -1) {
var imgType = items[i].type.split('/')[1];
var isAccepted = acceptedImgTypes.some(function (item) {
return imgType === item;
});
if(!isAccepted){
var acceptedTypeString = '';
acceptedImgTypes.forEach(function (item,i) {
acceptedTypeString += item;
if(i !== acceptedImgTypes.length - 1) acceptedTypeString+=',';
});
alert('Такое расширение файла не поддерживается,только '+acceptedTypeString+", тип файла - "+imgType);
continue;
}
// представляем изображение в виде файла
var blob = items[i].getAsFile();
console.log(blob);
filesArr.push(blob);
}
}
console.log(filesArr);
downloadFileToServer(filesArr);
}
// для Firefox проверяем элемент с атрибутом contenteditable
} else {
setTimeout(checkInput, 1);
}
}
Answer the question
In order to leave comments, you need to log in
Apparently in chrome this API is not yet fully implemented. Here's one and two .
Everything works in Safari. Well, it's better not to use experimental functions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question