我开始使用DropzoneJS这是一个很棒的开源库 7,043 stars上Github 。它提供带有图像预览的拖放文件上传。
但是,上传超过 100k 的图像会导致 Firefox
出现以下错误:
IndexSizeError: Index or size is negative or greater than the allowed amount
在 dropzone.js 中,在以下行中引发:
return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);
其他人报告说在创建缩略图时遇到了这种行为 here 。
经过一番研究后,这是 Firefox 中的一个常见错误。最相关的 stackoverflow 问题:
1- Canvas - IndexSizeError: Index or size is negative or greater than the allowed amount
最佳答案
按照此快速操作后解决了我的问题 fix 。
基本被替换:
return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);
与:
return ctx.drawImage(img, Math.round(sx), Math.round(sy), Math.round(sw), Math.round(sh), Math.round(dx), Math.round(dy), Math.round(dw), Math.round(dh) / vertSquashRatio);
在我的dropzone.js
关于javascript - DropzoneJS-索引大小错误: Index or size is negative or greater than the allowed amount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28036297/