monorepo-microservice-rbac/apps/dmp/public/uploadWorker.js
2023-08-27 14:37:59 +08:00

28 lines
599 B
JavaScript

/* eslint-disable */
self.onmessage = function (e) {
const files = e.data;
const promises = [];
for (let file of files) {
promises.push(readFile(file));
}
Promise.all(promises).then(results => {
self.postMessage(results);
});
}
function readFile(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = function (e) {
resolve({
name: file.name,
data: e.target.result
});
};
reader.onerror = reject;
reader.readAsDataURL(file); // 或者使用其他方法如 readAsArrayBuffer
});
}