javascript - How to handle large image files in file input JavaScript
问题描述
i have image file to upload into my react apps.
image =
size: 28mb
resolution: 8xxx x 12xxx
onFileChange(e){
const imageFile = e.target.files[0]
const imageBase64 = fileToBase64(imageFile)
let img = new Image()
img.onload = () => {
const canvas = document.createElement("canvas")
const ctx = canvas.getContext("2d")
// crop process ... (vanilla js)
canvas.drawImage(...)
return canvas.toDataURL()
}
img.src = imageBase64
}
my react apps always glitch when drawImage. sometimes crash the tab browser
tried in :
- macOS : chrome displaying "something went wrong while displaying this webpage"
- windows 10 : chrome glitch while load the image and displaying black image on canvas
or, any limit size for load image in javascript / canvas / others ?
解决方案
推荐阅读
- visual-studio - 从 Visual Studio 2019 中选择或更改 APK V1 签名方案
- javascript - 如何使用 JS/JQ/ 从 Marquee 获取值以显示在标签中
- java - 保持文件夹结构完整 Zip 任务 (Ant)
- javascript - 从 txt 或 json 文件向 js 脚本添加值
- c# - ASP.NET Core 3.1“无法从根提供程序解析范围服务。”
- python-3.x - Discord.py:MissingRequiredArgument:self 是缺少的必需参数
- python - 如何在函数中访问fastapi中间件中定义的request_id
- php - 如何通过woocommerce中的属性获取变体ID
- reactjs - 在 React 中将函数从祖父母传递给孙子孙女
- swift - 尝试使用 AVCapturePhotoOutput 时“没有活动和启用的视频连接”